<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by NeoKree on Medium]]></title>
        <description><![CDATA[Stories by NeoKree on Medium]]></description>
        <link>https://medium.com/@neokree?source=rss-6dcaeb71c455------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*XIMKH8gvj8meEUwCfbuHbA.jpeg</url>
            <title>Stories by NeoKree on Medium</title>
            <link>https://medium.com/@neokree?source=rss-6dcaeb71c455------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Thu, 19 Nov 2026 03:56:49 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@neokree/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Debugging a  ReactPHP application]]></title>
            <link>https://medium.com/@neokree/debugging-a-reactphp-application-57a33e66b56d?source=rss-6dcaeb71c455------2</link>
            <guid isPermaLink="false">https://medium.com/p/57a33e66b56d</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[xdebug]]></category>
            <category><![CDATA[reactphp]]></category>
            <category><![CDATA[phpstorm]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[NeoKree]]></dc:creator>
            <pubDate>Mon, 29 Apr 2019 17:07:30 GMT</pubDate>
            <atom:updated>2019-04-29T17:07:30.701Z</atom:updated>
            <content:encoded><![CDATA[<h3>Debugging a ReactPHP application</h3><h4>With xDebug, PHPStorm and Docker on MacOS</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*zaP2_VOx72G7AaX9" /><figcaption>Photo by <a href="https://unsplash.com/@maxcodes?utm_source=medium&amp;utm_medium=referral">Max Nelson</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>Trying new things it has always been an hobby for me, and today I was looking for new ways to create PHP applications, and in particular how to deal with asynchrony. Historically, PHP has always been synchronous and single process. Everything will always go from top to bottom. No exceptions.</p><p>But then,<a href="https://reactphp.org/"> ReactPHP</a> came into play.</p><p>Allowing PHP to make his own server, handling their processes, having his own event loop was like to rethink what PHP have ever been.</p><p>Obviously, the workflow and the development tools have to keep up with this new way of doing things. We are here to configure the most useful instrument for a developer: <strong>The debugger</strong></p><h4>The setup</h4><p>OS: MacOS <br>IDE: PhpStorm 2019.1<br>Debugger: Xdebug 2.7.1<br>PHP version: 7.3<br>Docker: 18.09.5<br>Docker Machine: 0.16.1</p><h4>The application</h4><p>We will use PHPStorm to debug this simple ReactPHP application:</p><pre>&lt;?php<br>require &#39;vendor/autoload.php&#39;;<br><br>$loop = React\EventLoop\Factory::<em>create</em>();<br><br>$server = new React\Http\Server(function (Psr\Http\Message\ServerRequestInterface $request) {<br><br>    return new React\Http\Response(<br>        200,<br>        array(&#39;Content-Type&#39; =&gt; &#39;text/plain&#39;),<br>        &quot;Hello World!\n&quot;<br>    );<br>});<br><br>$socket = new React\Socket\Server(&#39;0.0.0.0:8080&#39;, $loop);<br>$server-&gt;listen($socket);<br><br>echo &quot;Server running at http://0.0.0.0:8080\n&quot;;<br><br>$loop-&gt;run();</pre><p>As you can see, it will start a standard React webserver using the default eventloop, listening on <strong>0.0.0.0</strong> on port 8080 and always sending an “Hello world!” response to each request.</p><p>Before debugging, we need to be able to run it. For this tutorial I will use docker to create a custom image containing PHP 7.3, because I don’t want to have multiple PHP configuration on my mac. Also, this method will pay off if we will ever need to change OS and executing this project on Windows, for example.</p><p>Now, create a new Dockerfile in the build/php folder of the project<br><em>(I like to keep Dockerfiles in a subfolder to avoid having a messy root folder)</em></p><pre>FROM php:7.3-alpine<br><br># Install PHP extensions<br>RUN apk add --no-cache zip libzip-dev \<br>    &amp;&amp; docker-php-ext-install pdo_mysql zip<br><br># Install composer<br>RUN  curl -sS https://getcomposer.org/installer | php \<br>    &amp;&amp; mv composer.phar /usr/bin/composer<br><br># Install xdebug<br>RUN apk add --no-cache $<em>PHPIZE_DEPS </em>\<br>    &amp;&amp; pecl install xdebug-2.7.1 \<br>    &amp;&amp; docker-php-ext-enable xdebug \<br>    &amp;&amp; echo &#39;xdebug.remote_enable=1&#39; &gt;&gt; /usr/local/etc/php/conf.d/docker-php-ext-xdebug.ini<br><br>WORKDIR /app</pre><p>Note the xdebug.remote_enable=1 configuration, it will enable us to use xdebug (along with some other configurations from our IDE).</p><p>Also, if you are familiar with dockerfiles, you also see missing the COPY statement of our code. This is because in development, we don’t want to build our image every time a new code changes, so we will just use volumes to map our project folder on the /app folder in the container.</p><p>Now we can call the build method. Time for a coffe ☕️</p><pre>docker build -t my-app-name -f build/php/Dockerfile .</pre><p>Ok here we go. Now we have our image, but we need to download ReactPHP<br>To do so we will start an anonymous container telling him to execute a composer require react/http :</p><pre>docker run --rm -v $(pwd):/app my-app-name composer require react/http</pre><p>Now we should have the vendor folder and composer.json file in our project folder. Our project is now ready for..</p><h3>Execution</h3><p>Before debugging, we want to be able to execute our code. <br>Since ReactPHP will start his own long lived process, we will not start a webserver like apache and then expect them to find our files and executing our php files. We will need to start the webserver ourselves.</p><p>For “normal” PHP developers, this means that our application is essentially a command line interface, but that will continue processing until stopped by us.</p><p>So we will configure PHPStorm to use it that way</p><h4>The interpreter</h4><p>Since we will use the docker image to avoid multiple PHP configuration on the computer, we start by going to <em>Preferences → Language &amp; Frameworks → PHP</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QY_v2yj889ofeDwcc2OgRg.png" /></figure><p>Now we need to add the remote interpreter<br><em>(in my case the image is named </em><em>reactive-app)</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7-Z5BXWhK_1dZ74l4YiAHw.gif" /></figure><p>At the end of the check, we should have this situation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/997/1*vdqg7qeucFd9B_g90c7K8Q.png" /></figure><p>As you can see, PHPStorm already know that XDebug 2.7.1 is installed.</p><h4>Port &amp; path mapping</h4><p>Now that the interpreter is configured, we need to be able to communicate with it, after the application has been started.</p><p>This means we need to configure the port binding between the container which run our application and our computer host.</p><p>Also, we need to change the default /opt/project path mapping which PhpStorm set up for us, and use our previous configured /app path.</p><p>To do so we add some additional configuration of the docker container:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*qVBXbCO9INFaWWQ6ycQSUg.gif" /></figure><h4>The run script</h4><p>Ok one last step. We need to tell PhpStorm which script to run.<br>Right click on our application script (mine is called main.php) and tell PhpStorm to run it with the option <em>Run → PHP Script</em>.</p><p>We can finally test our ReactPHP application</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x8O20uDFcHdHK1HHXhQWZA.gif" /></figure><p>In my case, I used the command curl http://docker-host:8080 to curl the server, because I am using docker-machine with virtualbox (I added docker-host to my /etc/hosts to avoid remembering the IP address every time).</p><p>If you are using <a href="https://docs.docker.com/docker-for-mac/">Docker Desktop for Mac,</a> you can just run curl http://localhost:8080 instead.</p><h3>Debugging</h3><p>Now that we can run our ReactPHP application, we need to configure xDebug to communicate with PHPStorm, through docker.</p><p>Since we already have an image with xDebug installed, we just need to add some configuration to enable the communication between the two.</p><h4>The PHPStorm server configuration</h4><p>The first thing we need to do is setup the server configuration of PHPStorm.</p><p>You can find it here: <em>Preferences → Language and Frameworks → PHP → Servers.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*SzXwkymAdNET6UrjTvWHrQ.gif" /></figure><p>An important configuration is the path mapping. This will tell xDebug how to map the files inside the container to the one in our project.</p><p>The other important configuration is the server name (in my example is <strong>docker</strong>. You can name it what you want, though). This one will be send to the docker container at startup, telling xDebug which server IDE setting search for.</p><h4>CLI Interpreter (again)</h4><p>To set it, we need to return back to the CLI interpreter configuration</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*G60mHyZrKiNaJLVEN4fMeA.gif" /></figure><p>Setting up the PHP_IDE_CONFIG environment variable with the server value: serverName=docker .</p><h4>For Docker Machine…</h4><p>If you have an old mac (like mine) and are using docker-machine , you need to add an additional configuration to finish the debugger configuration:</p><blockquote>Setup the remote host.</blockquote><p>The remote host is a configuration that tells xDebug (from inside the container) to which IP address should it connect to debug the code. The default value is set up as localhost , but with docker-machine we are using a virtual machine to host the containers. So localhost points to the virtual machine, which is not where the code resides.</p><p>To make it work, we need to set the IP of the mac in our local network as receiver, so xDebug will attach to the correct host.</p><p>You can find it using the <em>Network</em> Section in the <em>System Preferences</em> app.<br> In my case is 192.168.1.20</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/862/1*cFw-bN7IPfuI-XtVNA4cVw.png" /></figure><p>Then, we can finally setup the xdebug.remote_host configuration for xDebug, editing the debugger options of the interpreter itself <em>(click on the three dots button to open the list of CLI interpreters).</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZMfG8MQV6Rgvrjp7H1yAzg.gif" /></figure><h3>Debug time!</h3><p>Now that we have done plenty configurations, let’s see if it works:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v3vvnAkawWHXx1HqrLT9eg.gif" /></figure><p>And it works! Happy debugging!</p><h4>Ending notes</h4><p>If you have experience with debugging in a “normal” PHP application you may be a little curious about why we did not have to enable the Listening to PHP connection option.</p><p>This is not needed because that option will try to connect to a webserver which is already running (like apache). In our case, we need to start the server for debugging, not to enable debug for a single HTTP request.</p><p>This also change another thing: You need to enable your breakpoint <strong>before </strong>starting your application.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=57a33e66b56d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A PrestaShop module development automation journey — Part 2]]></title>
            <link>https://medium.com/@neokree/a-prestashop-module-development-automation-journey-part-2-8a597a6cd8b5?source=rss-6dcaeb71c455------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a597a6cd8b5</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[installation]]></category>
            <category><![CDATA[docker]]></category>
            <dc:creator><![CDATA[NeoKree]]></dc:creator>
            <pubDate>Mon, 30 Jul 2018 12:03:34 GMT</pubDate>
            <atom:updated>2022-10-23T12:54:55.941Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rEYiC5sc8AUQHwjNmVNHFg.jpeg" /></figure><p><em>Install a testing suite</em></p><p><strong>Links: </strong><a href="https://gitlab.com/neokree/testmodule"><strong>Code in GitLab</strong></a></p><h4>Journey map:</h4><ul><li><a href="https://medium.com/@neokree/prestashop-module-development-automation-journey-part-1-1e52f9031b97">Part 1 — <em>Configuring local development using Docker Compose</em></a></li><li>Part 2 — Install a testing suite ← <strong>You are here</strong></li><li>Part 3 — Write automated tests</li></ul><h4>Note for the reader:</h4><p>I wanted to write an article about how to write automated tests for a prestashop module. However in this process I found complicated just to install the testing suite, so I split up the two articles to avoid writing a too long article.</p><h3>Choosing the tools</h3><p>For automated testing I have chosen <a href="https://codeception.com/">Codeception</a>. <br>There are other alternatives, like PHPUnit, Behat or PHPSpec… <br>But in the end, I wanted to keep the things simple and Codeception let you create tests of all types, from unit to acceptance tests. This is the main reason for my choice.</p><p>For installing Codeception, we need to use composer , which is the official PHP dependency manager. <br>If you don’t know what it is, this article should answer all your questions:</p><p><a href="https://scotch.io/tutorials/a-beginners-guide-to-composer">A Beginner&#39;s Guide To Composer</a></p><h3>Installing Composer</h3><p>Normally, to install composer, we need to first download it as a php archive (aka .phar ), using a command like this:</p><pre>curl -sS https://getcomposer.org/installer | php</pre><p>But this will install composer in our local project for our system PHP version. If you read the first part of this journey, you already know that our development configuration is all stored inside <strong>docker containers</strong>. So we don’t need to have PHP 5.6 installed on our machine, and everyone will use the exactly same php version. <em>(someone yelled multiple projects?)</em></p><p>So what are the other choices?</p><p>The first one is using a docker image. Composer have an <a href="https://hub.docker.com/_/composer/">official image</a> in docker hub. But there is a problem: It uses PHP 7 and there is not a PHP 5.6 tag. <em>(Actually, the deprecated </em><em>composer/composer image have it, but it uses an old composer version and it will not be update in the future, so I don’t think it is a mantainable choice.)</em></p><p>The second solution is installing composer directly from one of our prestashop websites. But this would mean we need to enter in the prestashop container using bash, move into the directory module, running the composer command and exit from the container every time we need to do something with composer. Too many commands for something that should be simple.</p><p>The third one is creating our custom composer docker image, but with PHP 5.6. It is much more complicated to setup, but after the first time we can just use it. And if another guy want to start develop with us, we can just build the image again in his system and run it.</p><p>I will explore the third solution, because I think it is the most scalable with multiple developers working on the same project.</p><h4>Creating the docker image</h4><p>We need an image that is exactly the same to the official one but with PHP 5.6, the first thing that came to my mind was to copy paste the dockerfile of the official image and change the FROM command, but after browsing for a while I discovered that the old deprecated composer/composer image was about half smaller, compared with to our builded image. Since I have an iMac with SSD, I would like to save some space if possible.</p><p>However, we need to store this dockerfile somewhere. Since we would have more dockerfiles in the future, I choose to create a build folder in the root of our project, under where we will create another subfolder called composer that will store the dockerfile.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/334/1*SlgFQb5O6l1WWonFqXqAxg.png" /></figure><p>This is the final result, with a size of 71 MB:</p><blockquote>build/composer/Dockerfile</blockquote><pre><strong>FROM </strong>php:5.6<strong>-</strong>alpine<br><br><strong>ENV </strong><em>COMPOSER_ALLOW_SUPERUSER </em>1<br><strong>ENV </strong><em>COMPOSER_HOME </em><strong>/</strong>tmp<br><br><strong>RUN </strong>apk add <strong>--</strong>no-cache <strong>--</strong>virtual git subversion openssh mercurial tini bash patch \<br> <strong>&amp;&amp; </strong>echo &quot;memory_limit=-1&quot; <strong>&gt; </strong>&quot;$<em>PHP_INI_DIR</em>/conf.d/memory-limit.ini&quot; \<br> <strong>&amp;&amp; </strong>echo &quot;date.timezone=${<em>PHP_TIMEZONE</em>:<strong>-</strong>UTC}&quot; <strong>&gt; </strong>&quot;$<em>PHP_INI_DIR</em>/conf.d/date_timezone.ini&quot; \<br> <strong>&amp;&amp; </strong>apk add <strong>--</strong>no-cache <strong>--</strong>virtual .build-deps zlib-dev \<br> <strong>&amp;&amp; </strong>docker-php-ext-install zip \<br> <strong>&amp;&amp; </strong>runDeps=&quot;$( \<br>    scanelf --needed --nobanner --format &#39;%n#p&#39; --recursive /usr/local/lib/php/extensions \<br>    | tr &#39;,&#39; &#39;\n&#39; \<br>    | sort -u \<br>    | awk &#39;system(&quot;[ <strong>-</strong>e <strong>/</strong>usr<strong>/</strong>local<strong>/</strong>lib<strong>/</strong>&quot; $1 &quot; ]&quot;) == 0 { next } { print &quot;so:&quot; $1 }&#39; \<br>    )&quot; \<br> <strong>&amp;&amp; </strong>apk add <strong>--</strong>virtual .composer-phpext-rundeps $<em>runDeps </em>\<br> <strong>&amp;&amp; </strong>apk del .build-deps \<br> <strong>&amp;&amp; </strong>rm <strong>-</strong>rf <strong>/</strong>var<strong>/</strong>cache<strong>/</strong>apk<strong>/* </strong>\<br> <strong>&amp;&amp; </strong>curl <strong>-</strong>sS https:<strong>//</strong>getcomposer.org<strong>/</strong>installer | php \<br> <strong>&amp;&amp; </strong>mv composer.phar <strong>/</strong>usr<strong>/</strong>bin<strong>/</strong>composer<br><br><strong>WORKDIR /</strong>app<br><br><strong>CMD </strong>[&quot;-&quot;]<br><strong>ENTRYPOINT </strong>[&quot;composer&quot;]</pre><p>So now we can just build the image</p><pre>docker build -t neokree/composer ./build/composer/</pre><p>After the process, we can finally install composer using our docker:</p><pre>docker run --rm -it neokree/composer init</pre><p>And composer will start the config generator:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hyKTGEPcGExmVUycdyfq1Q.png" /></figure><h3>Installing CodeCeption</h3><p>When the procedure ends, we can finally install the test automation suite:</p><pre>docker run --rm -it neokree/composer require codeception/codeception --dev</pre><p>Voilà, we now have installed locally the test suite, only for our development environment.</p><p>Following the <a href="https://codeception.com/quickstart">quick start</a> of the suite, we can now bootstrap it, creating all necessary test directories, using this command:</p><pre>./vendor/bin/codecept bootstrap</pre><p>But again, this will use our local PHP version. So we need to use the php:5.6-alpine image to create a container on the fly and use it instead of our local one.</p><pre>docker run --rm -it -v $PWD:/app -w /app php:5.6-cli-alpine ./vendor/bin/codecept bootstrap</pre><p>Even if this command works, I think that you are a little upset about the lenght of these command (just as I am), there should be a way to avoid call docker run --rm -it and a lot of other parameters to do something.</p><h3>Make it easy</h3><p>To make things easies, we need to wrap the complicated docker commands under a clean interface, like the original command interface we would have if we just installed everything locally. We need a gateway.</p><p>There are multiple ways to do this:</p><ul><li>Aliases</li><li>Makefile</li><li>Bash scripting</li></ul><p>But we are PHP developers. PHP is a scripting language. Why we cannot use it for write a script that wraps these commands?</p><p>Sure, in that case our script will use the default PHP version of the system, but I think this is acceptable. Every linux distribution, or macOS version that I know have it already installed as default. So I choose this path.</p><p>First, we need a place where store our scripts. Taking a cue from linux, I create a folder called bin in the root of our project. Inside it we will start to create our binaries:</p><h4>The composer script</h4><p>Inside the folder we will create a composer <em>(without extension)</em> file to wrap composer commands. But we should define how we will use it first, so we know what and how to implement it.</p><p>Since is a bin folder, I would like to be able to use it directly calling it from php, as well to call it like an application, as well as including in my PATH, like all other system applications. Some examples:</p><p>Call from PHP:<br>php bin/composer install</p><p>Call as application:<br>./bin/composer install</p><p>Add to our local PATH and use it:</p><pre>export PATH=$PWD/bin:$PATH<br>composer install</pre><p>Ok now we know what we want, let’s start thinking how to do it.</p><p>So the script will:</p><ul><li>Build the docker image if not already built</li><li>Pass the composer arguments to our composer docker container</li><li>Show the composer output</li></ul><p>It is not a lot of work, we just need to work a bit with shell_exec and/or system functions to make it work. But since we need to reuse some commands in the next script, we will abstract some functions for the future into a lib/docker.php file.</p><p>This is the end result:</p><blockquote>bin/composer</blockquote><pre>#!/usr/bin/env php<br><strong>&lt;?php<br>include_once</strong>(&#39;lib/docker.php&#39;);<br><br>$imageName = &#39;neokree/composer&#39;;<br>$arguments = implode(&#39; &#39;, array_slice($argv, 1));<br>$projectPath = realpath(<em>__DIR__</em>.&#39;/../&#39;);<br><br><strong>if </strong>(dockerImageDoesNotExist($imageName)) {<br>    <strong>print </strong>&quot;Composer image not found.\n&quot;;<br>    <strong>print </strong>&quot;Start building it. This may take a while...\n&quot;;<br><br>    $dockerfileFolderPath = $projectPath.&quot;/build/composer/&quot;;<br>    buildDockerImage($imageName, $dockerfileFolderPath);<br>}<br><br>$returnVal = executeCommandInDockerContainer($arguments, $imageName);<br><br><strong>exit</strong>($returnVal);</pre><blockquote>bin/composer/lib/docker.php</blockquote><pre><strong>&lt;?php<br><br></strong><em>/**<br> * </em><strong><em>@param </em></strong><em>string $imageName<br> * </em><strong><em>@return </em></strong><em>bool<br> */<br></em><strong>function </strong>dockerImageDoesNotExist($imageName)<br>{<br>    <strong>return </strong>trim(shell_exec(&quot;docker image inspect $imageName:latest 2&gt; /dev/null&quot;)) === &#39;[]&#39;;<br>}<br><br><em>/**<br> * </em><strong><em>@param </em></strong><em>string $imageName<br> * </em><strong><em>@param </em></strong><em>string $dockerfileFolderPath<br> */<br></em><strong>function </strong>buildDockerImage($imageName, $dockerfileFolderPath)<br>{<br>    shell_exec(&quot;docker build -t $imageName $dockerfileFolderPath&quot;);<br>}<br><br><em>/**<br> * </em><strong><em>@param </em></strong><em>string $command<br> * </em><strong><em>@param </em></strong><em>string $imageName<br> * </em><strong><em>@return </em></strong><em>int<br> */<br></em><strong>function </strong>executeCommandInDockerContainer($command, $imageName)<br>{<br>    $returnVal = 0;<br>    system(&#39;docker run --rm -it -v $PWD:/app -w /app &#39;.$imageName.&#39; &#39;.$command, $returnVal);<br>    <strong>return </strong>$returnVal;<br>}</pre><p>One last thing: Remember to add the execution bits to the composer file, otherwise you will be able to use it only as argument to PHP.</p><p>As of the previous script, we want the codeception to be exactly like if we installed locally, but undeline we will pass everything into a docker container.</p><p>Since this time we don’t have to build nothing, the script will be much simpler:</p><blockquote>bin/codecept</blockquote><pre>#!/usr/bin/env php<br><strong>&lt;?php<br>include_once</strong>(&#39;lib/docker.php&#39;);<br><br>$imageName = &#39;php:5.6-cli-alpine&#39;;<br>$arguments = implode(&#39; &#39;, array_slice($argv, 1));<br><br>$command = &#39;vendor/bin/codecept &#39;.$arguments;<br>$returnVal = executeCommandInDockerContainer($command, $imageName);<br><br><strong>exit</strong>($returnVal);</pre><p>If you noted, this command will use our local codecept binary, installed through composer. So in a new installation we will need to remember to install it first.</p><p><em>This ends Part 2. Thanks for sticking around!</em></p><p>In Part 3, we will start to write automated tests<br>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a597a6cd8b5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A PrestaShop module development automation journey — Part 1]]></title>
            <link>https://medium.com/@neokree/prestashop-module-development-automation-journey-part-1-1e52f9031b97?source=rss-6dcaeb71c455------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e52f9031b97</guid>
            <category><![CDATA[docker-compose]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[automation]]></category>
            <category><![CDATA[prestashop-development]]></category>
            <category><![CDATA[prestashop]]></category>
            <dc:creator><![CDATA[NeoKree]]></dc:creator>
            <pubDate>Fri, 29 Jun 2018 23:38:20 GMT</pubDate>
            <atom:updated>2022-10-23T12:53:56.082Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*bfdAOOfmh5OD0HV6QqPAIA.jpeg" /></figure><p><em>Configuring local development using Docker Compose</em></p><p><strong>Links: </strong><a href="https://gitlab.com/neokree/testmodule"><strong>Code in GitLab</strong></a></p><h4>Journey map:</h4><ul><li>Part 1 — Automate development workspace configuration ← <strong>You are here</strong></li><li><a href="https://medium.com/@neokree/a-prestashop-module-development-automation-journey-part-2-8a597a6cd8b5">Part 2 — Install a testing suite</a></li><li>Part 3 — Write automated tests</li></ul><p>Prestashop module development has been difficult for a lot of time. <br>Your module needs to support an increasing number of PrestaShop versions, testing cannot be made without a running prestashop, and documentation is very limited, if you compare it to other open source frameworks/platforms.</p><p>The first time I had to send for approval my module to PrestaShop Addons it took me an entire week, no kidding.</p><p>But can automation really help? <br>Someone told me yes, so let’s try it.</p><h3>The goal</h3><p>The goal is to make a module ready to be approved on the <a href="https://addons.prestashop.com/">PrestaShop Addons</a>, automating everything possible from development to validation.</p><p>The “working” module will be generated by the <a href="https://validator.prestashop.com/generator">prestashop module generator</a>. Nothing fancy here.</p><h3>Development setup</h3><p>For development, we will use four PrestaShop websites, that are the mayor versions that should be supported at this time: 1.7.3 , 1.7.2 , 1.7.1 and 1.6.1 .</p><p>Normally, this is where you go to download and install on your machine a LAMP setup, I am on macOS, so I have used <a href="https://www.mamp.info/en/">MAMP</a> for this.</p><p>But this operation is time consuming and causes problems if you have multiple environment.</p><p>For example if you have two computer where you develop, and you want to switch between them. Or if you work in a team, your collegues may have a different setup (or a different OS), which leads to bugs like: “It works on my computer”.</p><p>Wouldn’t it be great if instead we can use a single command to start your prestashop websites, having the certain that everyone have the exact same configuration?</p><h3>Let the docker composition begin</h3><p><a href="https://docs.docker.com/compose/overview/">Docker compose</a> is a tool that help you run multiple applications in your machine, without actually install it on your machine.</p><p>Instead, applications are build as images, which are executed in running container started on your system. This is similar to use a virtual machine, but faster.</p><p>I’m not going to explain how docker compose works underground. There are plenty of articles for that. Instead I will focus on what matter to us: <br><em>Automated and replicable development configuration</em></p><p>To do so, I will create a file called docker-compose.yml in the root of our module:</p><pre><strong>version: </strong>&quot;3&quot;<br><br><strong>services:<br>  mysql:<br>    image: </strong>mysql/mysql-server:5.7<br>    <strong>restart: </strong>always<br>    <strong>environment:<br>      </strong>- MYSQL_RANDOM_ROOT_PASSWORD=1<br>      - MYSQL_USER=${DB_USER}<br>      - MYSQL_PASSWORD=${DB_PASSWD}<br>      - MYSQL_DATABASE=${DB_NAME}<br><br>  <strong>prestashop_1.6.1:<br>    image: </strong>prestashop/prestashop:1.6<br>    <strong>depends_on:<br>      </strong>- mysql<br>    <strong>ports:<br>      </strong>- 8080:80<br>    <strong>volumes:<br>      </strong>- .:/var/www/html/modules/${PS_MODULE_NAME}<br>    <strong>environment:<br>      </strong>- DB_SERVER=mysql<br>      - DB_PREFIX=ps161_<br>      - PS_DEV_MODE=${PS_DEV_MODE}<br>      - PS_INSTALL_AUTO=1<br>      - DB_USER=${DB_USER}<br>      - DB_PASSWD=${DB_PASSWD}<br>      - DB_NAME=${DB_NAME}<br>      - PS_FOLDER_ADMIN=${PS_FOLDER_ADMIN}<br>      - PS_DOMAIN=${PS_DOMAIN}:8080<br>      - PS_LANGUAGE=${PS_LANGUAGE}<br>      - PS_COUNTRY=${PS_COUNTRY}<br>      - PS_FOLDER_INSTALL=installed<br><br>  <strong>prestashop_1.7.1:<br>    image: </strong>prestashop/prestashop:1.7.1.0<br>    <strong>depends_on:<br>      </strong>- mysql<br>    <strong>ports:<br>      </strong>- 8081:80<br>    <strong>volumes:<br>      </strong>- .:/var/www/html/modules/${PS_MODULE_NAME}<br>    <strong>environment:<br>      </strong>- DB_SERVER=mysql<br>      - DB_PREFIX=ps171_<br>      - PS_DEV_MODE=${PS_DEV_MODE}<br>      - PS_INSTALL_AUTO=1<br>      - DB_USER=${DB_USER}<br>      - DB_PASSWD=${DB_PASSWD}<br>      - DB_NAME=${DB_NAME}<br>      - PS_FOLDER_ADMIN=${PS_FOLDER_ADMIN}<br>      - PS_DOMAIN=${PS_DOMAIN}:8081<br>      - PS_LANGUAGE=${PS_LANGUAGE}<br>      - PS_COUNTRY=${PS_COUNTRY}<br>      - PS_FOLDER_INSTALL=installed<br><br>  <strong>prestashop_1.7.2:<br>    image: </strong>prestashop/prestashop:1.7.2.4<br>    <strong>depends_on:<br>      </strong>- mysql<br>    <strong>ports:<br>      </strong>- 8082:80<br>    <strong>volumes:<br>      </strong>- .:/var/www/html/modules/${PS_MODULE_NAME}<br>    <strong>environment:<br>      </strong>- DB_SERVER=mysql<br>      - DB_PREFIX=ps172_<br>      - PS_DEV_MODE=${PS_DEV_MODE}<br>      - PS_INSTALL_AUTO=1<br>      - DB_USER=${DB_USER}<br>      - DB_PASSWD=${DB_PASSWD}<br>      - DB_NAME=${DB_NAME}<br>      - PS_FOLDER_ADMIN=${PS_FOLDER_ADMIN}<br>      - PS_DOMAIN=${PS_DOMAIN}:8082<br>      - PS_LANGUAGE=${PS_LANGUAGE}<br>      - PS_COUNTRY=${PS_COUNTRY}<br>      - PS_FOLDER_INSTALL=installed<br><br>  <strong>prestashop_1.7.3:<br>    image: </strong>prestashop/prestashop:1.7.3<br>    <strong>depends_on:<br>      </strong>- mysql<br>    <strong>ports:<br>      </strong>- 8083:80<br>    <strong>volumes:<br>      </strong>- .:/var/www/html/modules/${PS_MODULE_NAME}<br>    <strong>environment:<br>      </strong>- DB_SERVER=mysql<br>      - DB_PREFIX=ps173_<br>      - PS_DEV_MODE=${PS_DEV_MODE}<br>      - PS_INSTALL_AUTO=1<br>      - DB_USER=${DB_USER}<br>      - DB_PASSWD=${DB_PASSWD}<br>      - DB_NAME=${DB_NAME}<br>      - PS_FOLDER_ADMIN=${PS_FOLDER_ADMIN}<br>      - PS_DOMAIN=${PS_DOMAIN}:8083<br>      - PS_LANGUAGE=${PS_LANGUAGE}<br>      - PS_COUNTRY=${PS_COUNTRY}<br>      - PS_FOLDER_INSTALL=installed</pre><p>Wow, this configuration is huge. <br>Let’s break it down.</p><h4>services</h4><p>The yaml file will tell to docker-compose which <em>services </em>(aka applications) we want to run. There are five in our setup:</p><ul><li>mysql</li><li>prestashop_1.6.1</li><li>prestashop_1.7.1</li><li>prestashop_1.7.2</li><li>prestashop_1.7.3</li></ul><h4>image</h4><p>This is the docker image to download from <a href="https://hub.docker.com/">hub.docker.com</a>.</p><h4>depends_on</h4><p>All prestashop_* services depends on the mysql service, because all needs a mysql database to run, this ensure that if something happen to the mysql service, the other services will respond accordingly.</p><p>For our development, we don’t really need to keep things separate, so we will use the database prefix to fit our four PrestaShop websites in one database.</p><h4>ports</h4><p>This parameter map the internal prestashop 80 to our machine port, like 8080 . Since we are running all these websites at once the configuration points to ports from range 8080 — 8083</p><h4>volumes</h4><p>Volumes are a way to map a directory of our machine to the remote host. In our case, we will link the current directory (the one containg the module files) to the modules folder of all prestashop services.</p><h4>environment</h4><p>Each docker image have a number of environment variables, which can be configurable to fit our needs. All variables ${} values are stored in a special file called .env, that should be placed in the root of our project. If you are working in a team, this let everyone change the configuration to fit their needs (and should not be kept under version control).</p><p>An example of this file could be:</p><pre># Database<br>DB_USER=username<br>DB_PASSWD=password<br>DB_NAME=prestashop<br><br># Prestashop<br>PS_DOMAIN=localhost<br>PS_DEV_MODE=1<br>PS_FOLDER_ADMIN=adminPS<br>PS_MODULE_NAME=testmodule<br>PS_LANGUAGE=en<br>PS_COUNTRY=GB</pre><p><strong>NOTE:</strong> PS_MODULE_NAME should always be set equal the module name, because it will be used to link the current project folder to the modules/ folder inside prestashop containers.</p><h3>Start up everything</h3><p>Now that our configuration is done, we just need to execute this command in the terminal to start up all containers<em> (be sure to be on the project root first)</em>:</p><pre>docker-compose up</pre><p>If you haven’t take it yet, now it’s time for a coffee ☕️☕️</p><p>The first time docker will download all images, start the containers, load the database, install prestashop and start the webserver for each website. <br>This will take some time…</p><p>But don’t worry, it’s only for the first run. <br>From the second startup it will take just some seconds.</p><p>When finished, you should be able to see your prestashop 1.6.1 website opening the pagelocalhost:8080</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oQDVFnborHmKT1LeImttVQ.png" /></figure><h3>The Backoffice</h3><p>If you have used my .env example file, your admin folder should be renamed in adminPS for all your websites.</p><p>This means you can go to localhost:8080/adminPS and login.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZmcX9pvWeN8ZZRrvABYY1w.png" /></figure><p>We can now enter into the admin using the default prestashop credentials:</p><blockquote>Email: demo@prestashop.com<br>Password: prestashop_demo</blockquote><p>If you want, you can even customize the default account using some additional environment variable in your docker-compose.yml file. For more information check out the <a href="https://hub.docker.com/r/prestashop/prestashop/">prestashop docker hub page</a>.</p><p><strong><em>NOTE:</em></strong><em> I referenced only the prestashop 1.6.1 website. If you didn’t skip the ports explanation, you should already know that you can open </em><em>localhost:8081/adminPS for </em><em>1.7.1, </em><em>localhost:8082/adminPS for </em><em>1.7.2 and </em><em>localhost:8083/adminPS for </em><em>1.7.3</em></p><h3>What about module development?</h3><p>You are right. Configuration is cool, but we need to work easily.</p><p>But since we have already configured a volume between our project and all prestashop websites, you can just go to the modules page in the prestashop backoffice and find your module, like you fresh install it.</p><p>Also, every change that you make to your project files will be automatically found in all prestashop websites.</p><p>Does it look like an improvement in your PrestaShop development workflow?<br>Let me know with a comment below</p><p><em>This ends Part 1. Thanks for sticking around!</em></p><p>In part 2 we will install a testing suite using composer.<br>Stay tuned!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e52f9031b97" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>