<?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 Tihomir Tonov on Medium]]></title>
        <description><![CDATA[Stories by Tihomir Tonov on Medium]]></description>
        <link>https://medium.com/@ttonov?source=rss-c0a552d2ad4e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*Ka0dx6zatgunS9y7tFdPnw.png</url>
            <title>Stories by Tihomir Tonov on Medium</title>
            <link>https://medium.com/@ttonov?source=rss-c0a552d2ad4e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 18:54:14 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ttonov/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[Better Error Messages in Tests]]></title>
            <link>https://medium.com/donatix/better-error-messages-in-tests-2a6c04a4166e?source=rss-c0a552d2ad4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/2a6c04a4166e</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[tdd]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[phpunit]]></category>
            <dc:creator><![CDATA[Tihomir Tonov]]></dc:creator>
            <pubDate>Fri, 08 Mar 2019 16:12:59 GMT</pubDate>
            <atom:updated>2019-03-18T09:48:14.079Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DvJgeV_GHPkkA2aXq3Vr5g.png" /></figure><p>We all have encountered error messages in our test suits like, Failed asserting that null is not nullor Failed asserting that false is trueand we have no clue what is the reason and what we have broken.</p><p>Of course, under the error message there is the file name and the line number of the failed assertion, so we open the file and here is the content:</p><pre>$this-&gt;assertTrue($user-&gt;is_active);</pre><p>Aha, now we know what is the real error and hopefully how to fix it. And if we think this is an important path of our code and a commonplace to have errors, we might add an additional message to the assertion to be displayed when this assertion fails, like this:</p><pre>$this-&gt;assertTrue($user-&gt;is_active, &#39;The user should be active&#39;);</pre><p>So we made the test a bit better, but I would argue if this is the best bang for the buck and don’t encourage anyone to submit a big PR, which fixes all non-descriptive errors in their project. The goal here is to know about the tool and use it when you need it.</p><p>Now let’s see some more complicated examples:</p><h4>Enhancing array assertions</h4><p>We all know about assertCount(), assertContains() and assertNotContains(), but when it comes to asserting, that some DB record presents or not in the returned response it gets a bit tricky. One way to do it is to pluck the ids and assert on them, but when such a test fails, it only says Failed asserting that [1,2,3] not contains 2, which is not telling us anything.</p><p>So what we could do?</p><p>One way is to use some string column on the model as the key to pluck and assert on its contents. And to make it clear why the test fails, we will name the column with the reason the test fails. Here is an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/498ba1907b684e3d36bdb89431e2ba26/href">https://medium.com/media/498ba1907b684e3d36bdb89431e2ba26/href</a></iframe><p>This way if the test fails we will see from its output that the result contains the product named Too expensive, which should not be the case.</p><p>This trick also could be used for ordering, when naming items something like: <em>first, middle and last</em>, and when the test fails we will see an error like Failed asserting that [first, middle, last] is equal to [last, middle, first], which means we broke the ordering.</p><h4>Enhancing callback based assertions</h4><p>Laravel allows us to mock its facades and check if given action was performed. Even further we can pass an additional callback to perform some more checks on the data with which the action was performed. Too abstract? Let’s see an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d48abf69cdfb61a6aacc10434028820f/href">https://medium.com/media/d48abf69cdfb61a6aacc10434028820f/href</a></iframe><p>This is a really powerful and useful concept, but with one downside, when it fails it says The expected [CheckNotification] was not sent. Failed asserting that false is true.and we have no idea what the error is.</p><p>Let’s think about the possible errors:</p><ul><li>We sent the notification to the wrong notifiable</li><li>We sent the wrong notification</li><li>The notification data misses <a href="http://domain1.com/"><em>domain1.com</em></a></li><li>The notification data Includes <a href="http://domain2.com/"><em>domain2.com</em></a></li></ul><p>And even though we cannot do much for the first two from this list, they are much less likely to be the problem.</p><p>On the other hand, the error message for the second two cases could be changed easily. We could write the assertions for the cases and return trueat the end. If some of the assertions fail, an exception will be thrown by <em>phpunit</em> and better error will be presented to us. Here is the example from above rewritten in such a way:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/10b44d618eab7f54c542fb594b6b56cd/href">https://medium.com/media/10b44d618eab7f54c542fb594b6b56cd/href</a></iframe><p>Now if the test fails we will see an error like this: Failed asserting that [&#39;problem.com&#39;, &#39;normal.com&#39;] not contains &#39;normal.com&#39;, and we will immediately know what failed the test case, without debugging the content of the variables passed to the callback.</p><p>This approach also might be used with assertions on the parameters with whom some mocked method was called. Abstract again? Let’s see an example:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/35801d0ab7590447e1e9d28430ce46d9/href">https://medium.com/media/35801d0ab7590447e1e9d28430ce46d9/href</a></iframe><p>There is one thing to keep in mind if you are trying to use withArgs in <em>laravel </em>project. You have to upgrade to a newer version of <em>Mockery</em> because <em>laravel </em>uses an older one, and withArgsmethod on mocks is not available. In my case, the upgrade was painless and went without any problems.</p><p>With that being said I hope you liked the “tricks” I presented and you will try them in your own projects and have better errors when your tests fail.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2a6c04a4166e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/donatix/better-error-messages-in-tests-2a6c04a4166e">Better Error Messages in Tests</a> was originally published in <a href="https://medium.com/donatix">Donatix</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Null Object Pattern in Laravel]]></title>
            <link>https://medium.com/donatix/null-object-pattern-in-laravel-79ab109a3cee?source=rss-c0a552d2ad4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/79ab109a3cee</guid>
            <category><![CDATA[nullobjectpattern]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[Tihomir Tonov]]></dc:creator>
            <pubDate>Fri, 28 Sep 2018 12:28:18 GMT</pubDate>
            <atom:updated>2018-10-18T13:02:43.838Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zsYyIOPS3BH4ol33RStgGA.png" /></figure><p>There are many times when we take for granted the relations in our database or some fields in an external API, CSV file or other data source. And in such situations, we often receive some kind of <strong>NullPointerException</strong>.</p><p>Laravel with its convenient ORM might bring us in such troubles unless we are careful. Imagine a simple blog site where you have users who can write posts and you display the author’s name under the title. With Laravel, you just write <strong>$post-&gt;author-&gt;name</strong>, pretty cool right? But what happens when the author deletes his account. You might consider one of the following:</p><ul><li>Delete all user’s posts, but why losing such useful information without a valid reason?</li><li>Denormalize the posts table and save some of the user information there, for example, the name, so you never need to worry, if the user is there.</li><li>Use soft deletes and never delete the user, but this might be a problem with the new GDPR regulations. Furthermore, you need to remember to load the relation with the trashed records. You can fix these problems if on delete you rename the user to “Unknown” and assign them a random email and password, but this is logic write.</li><li>Create a method on the blog post class which returns the author’s name, where you check for its existence and return some sensible default.</li></ul><p>As you can see, there are a lot of possible solutions and depending on the case you might need some of them or even another one which is not listed here. But I would like to present you an alternative, that you can use when you think you need it.</p><p>The Null Object Pattern is a design pattern, where some function/method returns an object or literal, that should act as a “null” version of the expected one. You can read more on <a href="https://en.wikipedia.org/wiki/Null_object_pattern">Wikipedia</a> about it. A simple example might be a function, that should return an array of items, which you want to filter, map over its items or just pass it into foreach. But what happens when there are no items to return? You might return null, but now you need to check, every time before performing, that foreach loop. The <em>null object</em> alternative would be to return an empty array and skip the check, just run the foreach.</p><blockquote><em>If you are using such techniques, you are implementing the pattern, so congrats on that.</em></blockquote><p>You can find the pattern implemented in many places in the framework. Some examples are the <strong>get()</strong> method of the <strong>Models</strong>, which always returns <strong>Collection,</strong> no matter if there are records or not, or the magic methods of the models, which allows you to access not existing properties. But more interesting are the methods, that allows you to specify, your own version of the <em>null value</em>. Here are some examples of such methods:</p><p>You can specify a default value to be returned, on the “to one” relations, as they would return null by default. This is done via the <strong>withDefault()</strong> method when defining the relation, which can even accept an array of params to make the model with, so it has some sensible defaults. If you don’t pass anything when no <strong>User</strong> is found, empty one will be returned.</p><p>Now we can call <strong>$post-&gt;author-&gt;name</strong>, without worrying if there is a user, and when a user deletes its account we can just delete it.</p><p>Of course, there are other solutions to the problem and you can argue if the default name should be specified in the relation method, or in some method for determining the author’s name. Here is how it might look using the <strong>??</strong> operator:</p><p>Bellow, I will describe some other functions which utilize the <em>null object pattern</em> across the framework.</p><p>They are really useful, when dealing with responses from other systems, reading files, accepting requests or every time you are not sure that the value will be there. There are two functions <strong>array_get</strong> and <strong>object_get</strong> for the different types of data structures. You should use <strong>array_get</strong> for associative arrays, no matter that <strong>object_get</strong> seems logical there. Here are 2 quick examples for both of them:</p><ul><li><strong>object_get($cloth, ‘brand’, ‘unknown brand’)</strong> — returns the <em>brand</em> property of the <em>cloth</em> object, if such exists, or <strong>unknown brand</strong></li><li><strong>array_get($colors, ‘black’, ‘000000’)</strong> — returns the value for the <em>black</em> key of the <em>colors</em> array or our default black value</li><li>another option is to simply use the <strong>??</strong> operator, which was introduced in php7, and simplify the code, even more, <strong>$colors[‘black’] ?? ‘000000’</strong></li></ul><p>Of course, you can use them without the default values and they will return <em>null</em> but will prevent exceptions about not defined indexes and items.</p><p>You can call the <strong>get()</strong> method on the <strong>$request</strong> object to receive the value of some input field, but it also accepts a second parameter, which is the default value returned, when the property does not exist. So <strong>$request-&gt;get(‘wants_emails’, false)</strong> return the value of <em>wants_emails</em> or <em>false</em>, if such is not defined. It could be also used with the <strong>request(‘wants_emails’, false)</strong> function if you prefer to use it.</p><p>Sometimes you might want to create “null” classes, which mimics the methods of the real implementation, but does “null”. You can implement all methods of the mimicked class or just a handful of them. This might be especially helpful in tests to replace some object. Another place to use the pattern might be when you have many similar classes and you don’t want to break the flow with null checks. If you create a class, that is instantiated in the null case, you can use it like the others and not clutter the code with null checks. In those cases, you can even implement common interfaces, if you are into it since it is a real class.</p><p>The <strong>optional()</strong> helper is another function, which helps to deal with nulls in the code, even tho it does not provide a way to specify a default value. Here is a little example where it can save us from unexpected exceptions, <strong>optional($user-&gt;address)-&gt;city</strong>. This way we will receive null even when there is no address property on the user class.</p><p>In conclusion, I hope that the next time you are wondering, how to deal with the possibility, of deleted relation or missing property of an API response, you would have one more weapon in your arsenal and don’t have to write <strong>if statement</strong>, because nobody likes them.</p><p><em>Originally published at </em><a href="https://donatix.net/null-object-pattern-laravel/"><em>donatix.net</em></a><em> on September 28, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=79ab109a3cee" width="1" height="1" alt=""><hr><p><a href="https://medium.com/donatix/null-object-pattern-in-laravel-79ab109a3cee">Null Object Pattern in Laravel</a> was originally published in <a href="https://medium.com/donatix">Donatix</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling Complicated Requests In Laravel]]></title>
            <link>https://medium.com/donatix/handling-complicated-requests-in-laravel-11c6c62ccaf3?source=rss-c0a552d2ad4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/11c6c62ccaf3</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[validation]]></category>
            <category><![CDATA[form-request]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[Tihomir Tonov]]></dc:creator>
            <pubDate>Tue, 10 Jul 2018 09:43:40 GMT</pubDate>
            <atom:updated>2018-10-18T13:01:51.549Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/804/1*51RVS_z9QXT1G0Dld-NteQ.png" /></figure><h3>Description of the problem</h3><p>Dealing with forms/requests on the web is one of the toughest problems to solve in the modern web, and as developers, we always seek ways to handle it in a more elegant way. But for education purposes most of the tutorials, we read/watch online, teach us how to deal with only simple requests. So that when we stumble upon some complicated request with <strong>20 fields</strong>, which should create <strong>5 types</strong> of models, we just don’t know what to do and <strong>dump all the logic in the controller</strong>.</p><p>This is a problem with the MVC architecture in general because it does not teach us where to put the complicated logic.</p><p>Let’s see some example of such <strong>complicated request</strong>, which we will be using in the post to address the problems and provide you with my solution.</p><blockquote><em>It again is simplified version of what really is possible, but I think is enough to explain the concept.</em></blockquote><h3>Example for a complicated request</h3><p>Let’s pretend we have an app where we have vehicles and we can create requests for parts for them, so someone can send us the needed parts. Here is the <strong>Object</strong> that we have:</p><ul><li>Vehicle — description of our car/motorcycle</li><li>Request — Links the parts to vehicle and author</li><li>Part — Description of the part needed, each request can contain more that one part</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/88c724956faa34255c7f620fd5d545bd/href">https://medium.com/media/88c724956faa34255c7f620fd5d545bd/href</a></iframe><p>After we saw the code and understand the domain let’s explore some methods to simplify it.</p><blockquote><em>TL;DR: You can jump straight to </em><strong><em>Form requests to the rescue</em></strong><em> if you don’t want to read my other solutions and what I think about them.</em></blockquote><h3>Possible solutions which are not always The Solution (Private methods, Service classes, Commands)</h3><h3>Long and hairy controller methods</h3><p>This is always a valid approach to do the work, especially when you don’t plan to revisit this method or controller, but since you are reading this article, you think you need a better approach, so let’s continue with the other options.</p><h3>Private methods in the controller</h3><p>This is maybe the best place to start. I like this approach because it keeps the logic in one class even though this is the controller. But we have some problems with this approach:</p><ul><li>the number of controller methods grow, which might be a problem, when we have 4–5 or more public methods and try to create some private ones for them</li><li>as these are controller methods they do not have access to the request data, as it belongs to the request object, and we should pass it from method to method. This makes such methods more like plain functions, which is always something to consider when deciding where to put a method.</li></ul><h3>Create a Dedicated Service classes</h3><p>The Service classes are something like an extension to the MVC architecture in some frameworks, but I personally don’t like them, because they are just one more <strong>buzzword</strong>. Don’t know where to put the logic, dump it into a <strong>Service Class</strong>, or worse, create a <strong>Service Class</strong> for each controller method.<br>Another problem with service classes is when you need to return a view from the controller with more than one variable/model/data source. In this case, we should return may be an associative array from the service class (which is practically the response), which in my opinion is a bit problem, because the service class takes the responsibility of the controller.<br>Of course, if we use them wisely they might be beneficial in some cases because we will have something like the approach with private methods in the controller, but without the problems. If we pass the request to the constructor, then we will be able to use its data in all the private methods of the service class, which solves the problems outlined in using private methods.<br>In our particular example, this approach might just do the job perfectly, but I think we can think of a better solution.</p><h3>Commands</h3><p>The problem with the whole <strong>Commands</strong> for saving <strong>Repositories</strong> for fetching concept, to me is that it is too complicated and overwhelming. In most of the cases simple <strong>Model::create([…])</strong> and <strong>Model::where(…)-&gt;get()</strong> work just fine.<br>Of course, the whole <strong>CQRS</strong> architecture has its place under the sun, but I definitely don’t think, we should go for it without really needing it.</p><h3>Form requests to the rescue</h3><p>As we know Laravel provides us with <strong>Form Request</strong> objects, which can be automatically injected in the controller method, and handle the validation and authorization logic of the request, so this can simplify our code a bit. The thing I don’t like here is, that we basically move the array of rules in another class and the validate method is called automatically for us, which is not enough to me. I want the form request to earn its existence. And also the <strong>ugly</strong> part of the work (the remapping of request fields to model fields) is still in the controller, which is really the thing, that bugs me.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/01a315cead13a7c631ac1d155401a18c/href">https://medium.com/media/01a315cead13a7c631ac1d155401a18c/href</a></iframe><p>So one thing we can do here is to move the mapping part of the code into some descriptive methods on the <strong>Form Request</strong> so it finally has <strong>more work to do</strong> to justify its <strong>existence</strong> and the code becomes much cleaner in my eyes.</p><p>The controller code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d73d1669813885560ec2b25d5d45b79f/href">https://medium.com/media/d73d1669813885560ec2b25d5d45b79f/href</a></iframe><p>The form request code</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/94332993c7a21ecb701f089dec428606/href">https://medium.com/media/94332993c7a21ecb701f089dec428606/href</a></iframe><p>With this approach we can handle transformations between HTML forms and DB/models format, switch between conventions (camelCase in js to snake_case in PHP/DB), selecting database records to fill some missing data, extracting other request info, or any other data when needed.</p><p>Last but not least, I don’t recommend this approach for each form on your project. Use it only when you need to store more models or have complicate request data massaging.</p><p>I even don’t recommend using Laravel’s Form Request classes just for validation, do it straight in the controller.</p><p><em>Originally published at </em><a href="https://donatix.net/handling-complicated-requests-laravel/"><em>donatix.net</em></a><em> on July 10, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=11c6c62ccaf3" width="1" height="1" alt=""><hr><p><a href="https://medium.com/donatix/handling-complicated-requests-in-laravel-11c6c62ccaf3">Handling Complicated Requests In Laravel</a> was originally published in <a href="https://medium.com/donatix">Donatix</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Code Coverage Reports with Phpunit]]></title>
            <link>https://medium.com/donatix/code-coverage-reports-with-phpunit-fd384becf155?source=rss-c0a552d2ad4e------2</link>
            <guid isPermaLink="false">https://medium.com/p/fd384becf155</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[phpunit]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[code-coverage]]></category>
            <dc:creator><![CDATA[Tihomir Tonov]]></dc:creator>
            <pubDate>Mon, 19 Mar 2018 16:03:15 GMT</pubDate>
            <atom:updated>2018-10-18T13:02:31.105Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*4d_3sWD8J1dxD_zRn7bN-w.jpeg" /><figcaption>code coverage report with phpunit</figcaption></figure><p>Recently we finished a green field project written in <strong>php</strong> with <strong>laravel</strong> as a framework, that was carried out under the <strong>Test Driven Development</strong> methodology right from the start. Test Driven Development is the preferred way for building high quality and scalable software. The biggest benefit is the ability to change the requirements and implementation and having a short feedback loop, of that if something went wrong. We decided to check its code coverage at the end, to have some idea about the amount of tests we have and how much of the code they cover. After some research, it turned out, that it is pretty simple.</p><p>You just need to have <strong>xdebug</strong> enabled and it will do all the heavy lifting.</p><h3>Enabling xdebug for testing</h3><p>If you are not sure, if you have <strong>xdebug</strong> enabled follow this paragraph, else you can proceed with the <strong>phpunit.xml</strong> update.<br> Run <strong>php –ini </strong>to find your <strong>xdebug</strong> configuration file. Mine is located in <strong>/usr/local/etc/php/7.0/conf.d/ext-xdebug.ini</strong><br> It should look like following snippet, if it is working.</p><pre>zend_extension=&quot;/usr/local/opt/php70-xdebug/xdebug.so&quot; xdebug.remote_enable = 1 xdebug.remote_autostart = 1</pre><p>After turning on <strong>xdebug</strong>, you don’t need to restart anything as we will be running the tests from the console.</p><h3>Phpunit configuration</h3><p>Since <strong>xdebug</strong> will do all the work, just add the following lines to your<strong> phpunit.xml</strong> file. I’ve added them bellow the <strong>listeners</strong> tag.</p><pre>&lt;logging&gt;<br>  &lt;log type=&quot;coverage-clover&quot; target=&quot;tests/_reports/logs/clover.xml&quot;/&gt;<br>  &lt;log type=&quot;coverage-html&quot; target=&quot;tests/_reports/coverage&quot; charset=&quot;UTF-8″ yui=&quot;true&quot; highlight=&quot;true&quot; lowUpperBound=&quot;35″ highLowerBound=&quot;70″ /&gt;<br>  &lt;log type=&quot;testdox-text&quot; target=&quot;tests/_reports/testdox/executed.txt&quot;/&gt;<br>&lt;/logging&gt;</pre><p>You might comment this section in development mode and use it only when you want to generate new report.</p><h3>Preparing the code coverage report</h3><p>To prepare the report just run <strong>phpunit </strong>in you project and wait for it to finish the execution.<br> You should be patient, because it was more than <strong>6 times slower</strong> for my project, than normal run of the tests with <strong>xdebug</strong> enabled.<br> Finally the results should appear in <strong>tests/_reports/coverage</strong>, where you will find <strong>index.html</strong> file, which you can use to start browsing your test coverage report.</p><h3>Tips on tests speed</h3><p>— If you are not a debugger just disable <strong>xdebug</strong> and your test suite will run so much faster (in my case around 4 times faster).<br> — If you are using <strong>laravel</strong> and its authentication system during tests, decrease the encryption algorithm complexity <strong>only for you tests</strong>, by adding the following line to your <strong>createApplication</strong> method located in <strong>tests\CreatesApplication</strong> trait, to make them run even faster (2x performance boost for me).</p><pre>Hash::setRounds(4);</pre><p>— You might use <a href="https://github.com/johnkary/phpunit-speedtrap">johnkary/phpunit-speedtrap</a> to report you which tests are running slow, so you can try to improove them.<br> — Finally this one is not speed related, but I really like it <a href="https://packagist.org/packages/codedungeon/phpunit-result-printer">codedungeon/phpunit-result-printer</a>. You might install this package to change the way executed tests are presented in the console.</p><p><em>Originally published at </em><a href="https://donatix.net/phpunit-code-coverage-reports/"><em>donatix.net</em></a><em> on March 19, 2018.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fd384becf155" width="1" height="1" alt=""><hr><p><a href="https://medium.com/donatix/code-coverage-reports-with-phpunit-fd384becf155">Code Coverage Reports with Phpunit</a> was originally published in <a href="https://medium.com/donatix">Donatix</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>