<?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 LaravelFeed on Medium]]></title>
        <description><![CDATA[Stories by LaravelFeed on Medium]]></description>
        <link>https://medium.com/@laravelfeed?source=rss-f737c1bdd1dc------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*GQSIw2xdsHtmDoisNWpsiw.jpeg</url>
            <title>Stories by LaravelFeed on Medium</title>
            <link>https://medium.com/@laravelfeed?source=rss-f737c1bdd1dc------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 14 Nov 2026 08:50:57 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@laravelfeed/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[Eloquent by Example]]></title>
            <link>https://medium.com/@laravelfeed/eloquent-by-example-373f9aa9548c?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/373f9aa9548c</guid>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[laravel-eloquent]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[tutorial]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Tue, 06 Dec 2016 08:43:37 GMT</pubDate>
            <atom:updated>2016-12-06T08:43:37.760Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/648/0*yzeSJsqbXsb01ggr.png" /></figure><p>3 minutes ago</p><p>Laravel is a great framework with fantastic documentation — but it can be a little overwhelming. There are so many ways to accomplish the same task. How do you know which way is the best?</p><p>This course will break down the most important things to learn about Eloquent, the ORM that is a central part of Laravel. There are 14 Lessons that take about 10–15 minutes each to accomplish.</p><p>At the end of the three weeks you will have a solid workflow and be able to use the Artisan tools to quickly design and create new applications.</p><h3>Who is this course for?</h3><p>This is for people who are relatively new to Laravel, are simply interested in learning more about the Eloquent ORM, or who feel like they missed out on some important things from teaching themselves and would like to learn some of the techniques they’ve seen on Laracasts or other tutorials.</p><h3>Lessons</h3><h3>About Jeff Madsen</h3><p>Jeff Madsen is a free-lance developer living in Japan. He blogs about Laravel, Vue.js and other web development. Follow him on <a href="https://twitter.com/codebyjeff">Twitter</a> or <a href="https://medium.com/@codebyjeff">Medium</a>, or join his weekly <a href="http://codebyjeff.com/newsletter">Laravel Quick Tips</a> newsletter to learn more about the framework.</p><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/eloquentbyexample"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=373f9aa9548c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP 7 performance improvements (4/5): References mismatch]]></title>
            <link>https://medium.com/@laravelfeed/php-7-performance-improvements-4-5-references-mismatch-fc5f8c07eb6d?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/fc5f8c07eb6d</guid>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[php7]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Tue, 06 Dec 2016 08:23:19 GMT</pubDate>
            <atom:updated>2016-12-06T08:23:19.796Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*fLPAW-aQXEZvw773.png" /></figure><p><a href="http://laravelfeed.com/blog/php-7-performance-improvements-references-mismatch#">PHP 7 performance improvements (4/5): References mismatch</a></p><p>Julien Pauli, PHP contributor and release manager, details what changed between PHP 5 and PHP 7, and how to migrate and make effective use of the language optimizations. All statements are documented with specific examples and Blackfire profiles. Fourth episode: References mismatch generating no overhead.</p><blockquote><em>The following is the 4th episode of our blog series on PHP 7 performance improvements, detailed by Julien Pauli PHP Contributor and Release Manager. We will update this introduction with links to all other articles when they are published.</em></blockquote><blockquote><em>Read episode 1: </em><a href="https://blog.blackfire.io/php-7-performance-improvements-packed-arrays.html?utm_source=laravelfeed.com"><em>Packed arrays</em></a></blockquote><blockquote><em>Read episode 2: </em><a href="https://blog.blackfire.io/php-7-performance-improvements-ints-floats-free.html?utm_source=laravelfeed.com"><em>ints/floats are free in PHP 7</em></a></blockquote><blockquote><em>Read episode 3: </em><a href="https://blog.blackfire.io/php-7-performance-improvements-35-encapsed-strings-optimization.html?utm_source=laravelfeed.com"><em>Encapsed strings optimization</em></a></blockquote><p>Reference mismatch happens when you pass a non-ref variable to a function argument passed-by-ref, or the opposite. Something like this:</p><pre>function foo(&amp;$arg) { } $var = &#39;str&#39;; foo($var);</pre><p>Do you know what horrible things happen under the hood in the PHP 5 engine? In PHP 5, whenever there is a reference mismatch, the engine is forced to duplicate the variable before passing it as an argument to a function. As you probably guessed, if the variable contains something big, like a several-thousands-entries array or a big chunk of string; the copy will take a lot of time.</p><p>This is because of the way variables and references used to work into PHP 5. When going into the body function, the engine doesn’t know yet if you will change the argument value. If you are, then as the argument is taken by reference, the change must be reflected outside if a reference variable were passed. What if it was not the case (as in our example)? The engine must then create a reference, from the non-reference variable you passed it in the function call. This procedure leads the engine to fully duplicate the variable content in PHP 5 (calling a lot of memcpy() on very sparse pointers, leading to tons of slow memory accesses).</p><p>In PHP 7, when the engine wants to create a reference from a non-reference variable, it just wraps the latter into the newly created former, that’s all. There is no memory copy, anywhere. This is because variables work in a very different way internally in PHP 7, and references have been deeply reworked.</p><p>Look at this piece of code:</p><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/php-7-performance-improvements-references-mismatch"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fc5f8c07eb6d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Delicious Evils of PHP]]></title>
            <link>https://medium.com/@laravelfeed/the-delicious-evils-of-php-2cb01cd95d35?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/2cb01cd95d35</guid>
            <category><![CDATA[oop]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[objects]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Tue, 06 Dec 2016 08:13:58 GMT</pubDate>
            <atom:updated>2016-12-06T08:13:58.751Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GdNiV65uQinzBzJ6rgyX3w.png" /></figure><p>I want to look at two PHP functions: eval and exec. They’re so often thrown under the sensible-developers-never-use-these bus that I sometimes wonder how many awesome applications we miss out on.</p><p>Like every other function in the standard library, these have their uses. They can be abused. Their danger lies in the amount of flexibility and power they offer even the most novice of developers.</p><p>Let me show you some of the ways I’ve seen these used, and then we can talk about safety precautions and moderation.</p><h3>Dynamic Class Creation</h3><p>The first time I ever saw dynamic class creation was in the bowels of <a href="https://www.codeigniter.com/">CodeIgniter</a>. At the time, CodeIgniter was using it to create ORM classes. eval is still used to <a href="https://github.com/bcit-ci/CodeIgniter/blob/4b94152a48d8053ab72669278abfec18e1793310/system/core/Loader.php#L969">rewrite short open tags</a> for systems that don’t have the feature enabled…</p><p>More recently, though, my friend <a href="https://twitter.com/adamwathan">Adam Wathan</a> tweeted about using it to dynamically create <a href="https://laravel.com/">Laravel</a> facades. Take a look at what the classes usually look like:</p><pre>namespace Illuminate\Support\Facades; class Artisan extends Facade { protected static function getFacadeAccessor() { return &quot;Illuminate\Contracts\Console\Kernel&quot;; } }</pre><p><em>This is from </em><a href="https://github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Artisan.php"><em>github.com/laravel/framework/blob/5.3/src/Illuminate/Support/Facades/Artisan.php</em></a></p><p>These facade classes aren’t facades in <a href="https://en.wikipedia.org/wiki/Facade_pattern">the traditional sense</a>, but they do act as static references to objects stored in Laravel’s <a href="https://laravel.com/docs/5.3/container">service locator class</a>. They project an easy way to refer to objects defined and configured elsewhere, and have benefits over traditional static (or singleton) classes. One of these benefits is in testing:</p><pre>public function testNotificationWasQueued() { Artisan::shouldReceive(&quot;queue&quot;) -&gt;once() -&gt;with( &quot;user:notify&quot;, Mockery::subset([&quot;user&quot; =&gt; 1]) ); $service = new App\Service\UserService(); $service-&gt;notifyUser(1); }</pre><p>…and though these facades are simple to create, there are a lot of them. That’s not the kind of code I find interesting to write. It seems Adam felt the same what when we wrote the <a href="https://twitter.com/adamwathan/status/801434366966636545">tweet</a>.</p><p>So, how could we create these facade classes dynamically? I haven’t seen Adam’s implementation code, but I’m guessing it looks something like:</p><pre>function facade($name, $className) { if (class_exists($name)) { return; } eval(&quot; class $name extends Facade { protected static function getFacadeAccessor() { return $className::class; } } &quot;); }</pre><p>That’s a neat trick. Whether of not you use (or even like) Laravel facades, I’m guessing you can see the benefits of writing less code. Sure, this probably adds to the execution time of each request, but we’d have to profile performance to decide if it even matters much.</p><p>I’ve used a similar trick before, when working on a functional programming library. I wanted to create the supporting code to enable me to write applications using fewer (if any) classes. This is what I used eval to create:</p><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/the-delicious-evils-of-php"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2cb01cd95d35" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Install Laravel Homestead on Windows Extremely Easily]]></title>
            <link>https://medium.com/@laravelfeed/install-laravel-homestead-on-windows-extremely-easily-d881ab38541f?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/d881ab38541f</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[windows]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[laravel-homestead]]></category>
            <category><![CDATA[vagrant]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Thu, 01 Dec 2016 08:26:40 GMT</pubDate>
            <atom:updated>2016-12-01T08:26:40.050Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/841/1*kqG3uHA-0kQ-3vtu5EmEcw.jpeg" /></figure><p>There are tons of reasons to do laravel development on Homestead. And though you might be convinced to use it, it is not always very simple to be “up and running” within minutes. Laravel’s official documentation on installing Homestead on Windows and Mac is pretty clear. But sometimes, the process is not as straight forward as shown in the documentation. There are a lot of 3rd party software involved and sometimes they create problems. I will be guiding you through the installation and configuration of Laravel Homestead while preventing the common errors from occurring.</p><h3>Introduction</h3><p>You may already know what Laravel Homestead is and what VirtualBox and Vagrant are. But just in case you don’t know then here is a brief introduction for them.</p><h3>VirtualBox:</h3><p>It is a software which helps you run a different Operating System on top of another Operating System. For example you have Windows installed on your machine and you want to use a Ubuntu on it as well. You can do it through VirtualBox. As the name Implies, it creates a Virtual Box or a Virtual Machine inside which you can install other operating systems. In this case, Windows will be your Host OS while Ubuntu will be your Guest OS.</p><h3>Vagrant</h3><p>Vagrant is a utility which help us automatically manage Virtual Machines inside Virtual Box. It also help us to ship our software to others or even to the production server with same environment in which we have coded it. Most of Php developers uses Windows or Mac to code on. The main problem with these OSs is that when we ship our software to a Linux environment, it breaks. Vagrant help us ship the software along the environment in an file format known as box e.g Homestead.box</p><h3>Laravel Homestead</h3><p>Homestead is a group of software and commands for Vagrant. The official list of what’s included in it can be found <a href="https://laravel.com/docs/5.3/homestead">here</a>. It automatizes and facilitates the installation of required software for a Virtual Server like Ubuntu, Nginx, MySQL etc.</p><p>In short, by combining VirtualBox, Vagrant and Laravel Homestead, one will be able to provide a production environment to Laravel inside Windows or Mac. So you can have all your favorite apps and software of your favorite OS along with the benefit of having a full fledged production level server running Ubuntu and Nginx. Now follow the following steps to get Laravel Homestead up on Windows.</p><h3>Step 1: Downloading Files</h3><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/laravel-homestead-windows-extremely-easy"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d881ab38541f" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[11 Courses to Help You Master PHP Frameworks]]></title>
            <link>https://medium.com/@laravelfeed/11-courses-to-help-you-master-php-frameworks-228b641bcc73?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/228b641bcc73</guid>
            <category><![CDATA[online-courses]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[framework]]></category>
            <category><![CDATA[laravel]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Thu, 01 Dec 2016 07:58:43 GMT</pubDate>
            <atom:updated>2016-12-01T07:58:43.794Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/900/1*Ej_6NKXAncQ-WjcnmW9w4A.jpeg" /></figure><p>PHP frameworks can really speed up your development process. They provide you with a stable foundation to start from, so that you can spend time developing the important parts of your application rather than reinventing the wheel.</p><p>But the proliferation of different PHP frameworks also means that there’s a learning curve involved. As well as learning PHP, you need to learn the workings of each framework, or at least of the ones you’re planning to use.</p><p>So we’ve got you covered in this article, with details of 11 courses that will get you up to speed with Laravel, Lumen, Phalcon, Symfony, and a range of other PHP frameworks.</p><h3>1. <a href="https://code.tutsplus.com/courses/get-started-with-laravel-5?ec_promo=learning_roundup">Get Started With Laravel 5</a></h3><p>Laravel is a PHP framework for modern web apps. Recently upgraded to version 5, Laravel is a mature system that continues to win support due to its elegance and stability. Laravel ships with built-in support for database migrations, object-relational mapping, routing, and authentication, making it easier for developers to start and maintain their work.</p><p>In this course, you’ll start by learning the basics of the Laravel framework with instructor Jason Lewis. You’ll begin by preparing a dev environment and learning how to configure Laravel. Then you’ll move on to learn foundational topics such as routing and requests, responses, views, sessions, emails, forms, and using databases.</p><h3>2. <a href="https://code.tutsplus.com/courses/build-a-cms-with-laravel?ec_promo=learning_roundup">Build a CMS With Laravel</a></h3><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/courses-to-help-you-master-php-frameworks"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=228b641bcc73" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP 7.1–8 New Features you need to know]]></title>
            <link>https://medium.com/@laravelfeed/php-7-1-8-new-features-you-need-to-know-32470c0a581b?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/32470c0a581b</guid>
            <category><![CDATA[php7]]></category>
            <category><![CDATA[features]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Thu, 01 Dec 2016 07:44:19 GMT</pubDate>
            <atom:updated>2016-12-01T07:44:19.602Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*nofSvr_dFfYXwMnZ.png" /></figure><p><a href="http://laravelfeed.com/blog/php-71-8-new-features-you-need-to-know#">PHP 7.1–8 New Features you need to know</a></p><p>4 minutes ago</p><p>PHP 7.1, the new minor version of PHP will be released on <a href="http://externals.io/thread/512">December 1st</a>, with a number of new features, changes, and bug fixes. While we wait for it’s release, let’s look at some of the awesome features in PHP 7.1. Like,</p><ul><li>iterable pseudo type</li><li>Closure from callable</li><li>Square bracket syntax for list()</li><li>Support for keys in list</li><li>Class constant visibility</li><li>Nullable types</li><li>Void functions</li><li>Catching Multiple Exception Types</li></ul><p>I will also link to the corresponding RFCs for your reference.</p><p><strong>Before we start:</strong> Would you like to try out PHP 7.1 without messing up the existing environment? Docker is your best friend! PHP 7.1 can be easily set up using <a href="https://www.docker.com/">Docker</a> with one of these <a href="https://hub.docker.com/_/php/">images</a>.</p><p>To start a php 7.1 container:</p><pre>docker run -v /Users/apple/Workplace/php/:/php -it php:7.1-rc bash</pre><p>This will download (if not locally existing) the docker image for php:7.1-rc, start the container and take you inside the container using bash prompt. -v /Users/apple/Workplace/php/:/php option maps /Users/apple/Workplace/php directory of the host machine to /php directory inside the docker container. So everything inside /Users/apple/Workplace/php will be available in /php directory of the container.</p><p>Now we will move inside the /php directory.</p><pre>cd /php</pre><p>Cool! We are now ready to try out the new features in PHP 7.1.</p><h3>iterable pseudo type</h3><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/php-71-8-new-features-you-need-to-know"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=32470c0a581b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing Laravel Middleware]]></title>
            <link>https://medium.com/@laravelfeed/testing-laravel-middleware-80f25fce931b?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/80f25fce931b</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[middleware]]></category>
            <category><![CDATA[php]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Wed, 30 Nov 2016 09:12:58 GMT</pubDate>
            <atom:updated>2016-11-30T09:12:58.043Z</atom:updated>
            <content:encoded><![CDATA[<p>It’s widely accepted that high-level integration tests alone do not make for a good test suite. Ideally each individual component of your application should have unit tests, which test that component in isolation. These unit tests are usually much quicker to run, making it easier to practice test-driven development. However, it can sometimes be hard to grasp how to test that one component on its own.</p><p>The other day I had an issue with several middleware classes for a Laravel application and I wanted to verify that they were working as expected. Sounds like a job for dedicated unit tests, but I hadn’t tested custom middleware in isolation before, and figuring out how to do so took a while.</p><p>Laravel middleware accepts an instance of Illuminate\Http\Request, itself based on the Symfony request object, as well as a closure for the action to take next. Depending on what the middleware does, it may return a redirect or simply amend the existing request or response. So in theory you can instantiate a request object, pass it to the middleware, and check the response. For middleware that does something simple, such as redirecting users based on certain conditions, this is fairly straightforward.</p><p>In this example we have a fairly useless piece of middleware that checks to see what the route is for a request and redirects it if it matches a certain pattern:</p><pre>namespace App\Http\Middleware; use Closure; class RedirectFromAdminMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if ($request-&gt;is(&#39;admin*&#39;)) { return redirect(&#39;/&#39;); } return $next($request); } }</pre><p>While this example is of limited use, it wouldn’t take much work to develop it to redirect conditionally based on an account type, and it’s simple enough to demonstrate the principles involved. In these tests, we create instances of Illuminate\Http\Request and pass them to the middleware’s handle() method, along with an empty closure representing the response. If the middleware does not amend the request, we get the empty response from the closure. If it does amend the request, we get a redirect response:</p><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/testing-laravel-middleware"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80f25fce931b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Using Traits With PHPUnit]]></title>
            <link>https://medium.com/@laravelfeed/using-traits-with-phpunit-cfc4d12aa5c5?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/cfc4d12aa5c5</guid>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[unit-testing]]></category>
            <category><![CDATA[traits]]></category>
            <category><![CDATA[phpunit]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Wed, 30 Nov 2016 09:04:53 GMT</pubDate>
            <atom:updated>2016-11-30T09:04:53.123Z</atom:updated>
            <content:encoded><![CDATA[<p>As we already wrote that <a href="https://qafoo.com/blog/063_code_reuse_by_inheritance.html">“Code Reuse By Inheritance”</a> has lots of problems and we consider it a code smell. You should always aim to use Dependency Injection, most likely Constructor Injection. But with test cases in PHPUnit we cannot do this because we have no control about how and when our test cases are created. There are a similar problem in other frameworks, like we discussed in <a href="https://qafoo.com/blog/020_object_lifecycle_control.html">“Object Lifecycle Control”</a>. We also blogged about <a href="https://qafoo.com/blog/072_utilize_dynamic_dispatch.html">traits as a Code Smell</a>, but let me show and explain why they might be fine to use in your test cases.</p><p>So in PHPUnit it is common to reuse code by inheritance. Even by now we often create some base class providing common functionality. This works fine and is OK if this really defines an “is a”-relationship. Let’s continue with an example from our <a href="https://github.com/QafooLabs/PageObjects">Page Object test repository</a>. The patterns described here are usually not required for Unit Tests (which you should always also write) but mostly for integration or functional tests.</p><h3>An Example</h3><p>The <a href="https://github.com/QafooLabs/PageObjects">example repository</a> implements functional tests for a website using the <a href="https://qafoo.com/blog/089_introduction_to_page_objects.html">Page Object pattern</a>. This means that the tests access a website and assert on its contents, try to fill forms, submit them and click links. Such tests are a useful part of <a href="https://qafoo.com/blog/055_finding_the_right_test_mix.html">your test mix</a>, but should never be your only tests.</p><p>Let’s see the options for code reuse we employ in this little test project — and the reasoning behind it. We start with a simple test case:</p><pre>class LoginTest extends FeatureTest { public function testLogInWithWrongPassword() { $page = (new Page\Login($this-&gt;session))-&gt;visit(Page\Login::PATH); $page-&gt;setUser(getenv(&#39;USER&#39;)); $page-&gt;setPassword(&#39;wrongPassword&#39;); $newPage = $page-&gt;login(); $this-&gt;assertInstanceOf(Page\Login::class, $newPage); } // … }</pre><p>This test case extends from a base class FeatureTest to re-use its functionality. The base class uses PHPUnits setUp() method to setup and start the mink test driver which will act as a browser to access the website. And it provides a default tearDown() method to reset the browser state again.</p><p>In this case the inheritance defines a clear “is a” relationship with the FeatureTest and it overwrites default methods in the PHPUnit stack which should be overwritten in any feature test. The FeatureTest again extends an IntegrationTest which is empty in this example but normally would provide access to the application stack to reset a database, access random services or something similar. We just do not need anything like this in this little test project. Since functional tests can be considered a superset of integration tests this is fine again and provides common functionality which belongs to all tests of this type.</p><h3>Traits</h3><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/using_traits_with_phpunit"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=cfc4d12aa5c5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How I refactor to collections]]></title>
            <link>https://medium.com/@laravelfeed/how-i-refactor-to-collections-9c40313aa2e9?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/9c40313aa2e9</guid>
            <category><![CDATA[php]]></category>
            <category><![CDATA[refactoring]]></category>
            <category><![CDATA[laravel]]></category>
            <category><![CDATA[source-code]]></category>
            <category><![CDATA[collection]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Wed, 30 Nov 2016 08:45:53 GMT</pubDate>
            <atom:updated>2016-11-30T08:45:53.630Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*pWsoeM-Inu5Jbrzm_2Stgw.png" /></figure><p><a href="https://adamwathan.me/refactoring-to-collections?utm_source=laravelfeed.com">Refactoring to Collections</a> is a great book by Adam Wathan where he demonstrates, how you can avoid loops by using collections. It sounds great from the beginning, but you need to practice it, in order to be able to use it in your own projects. This is why I refactored some of my older projects. I want to share these examples today with you.</p><p><strong>Note:</strong> Code examples are from Laravel projects where collections are built-in.</p><h3>Example 1</h3><p>Here I needed to built a string from an array to create an unique cache key for given search filters. When you first look at the before and after examples, you could question if the collection version is a better choice here. This is because it looks a little bit more complex. But this is just the first impression. The collection version of this code has some great benefits:</p><ul><li>as always with collections, the code tells you more about what is happening</li><li>it separates steps and helps you do one thing after the other</li><li>it is easier to add more functionality like adding a filter</li></ul><h4>Before</h4><pre>... $returnString = &#39;&#39;; foreach ($filters as $key =&gt; $item) { $returnString .= $key .&#39;:&#39; . $item . &#39;,&#39;; }</pre><h4>Afterwords</h4><pre>$returnString = collect($filters) -&gt;map(function($value, $key) { return $key . &#39;:&#39; . $value; })-&gt;implode(&#39;,&#39;);</pre><h3>Example 2</h3><p>This second example is from a private project of mine where I work with recipes and recipe steps. When you create a new recipe you need to store recipe steps too. We are mapping an input array of recipe step data to a new collection of recipeSteps objects. Collections are also great here, because we can use them with the saveMany method like this: $newRecipe-&gt;recipeSteps()-&gt;saveMany($recipeSteps);</p><h4>Before</h4><pre>... $steps = $input[&#39;step&#39;]; $recipeSteps = []; foreach ($steps as $step) { $recipeSteps[] = new RecipeStep([&#39;recipe_id&#39; =&gt; $recipeId, &#39;desc&#39; =&gt; $step[&#39;desc&#39;]]); }</pre><h4>Afterwords</h4><pre>... $steps = collect($input[&#39;step&#39;]) $recipeSteps = $steps-&gt;map(function($step) use ($recipeId) { return new RecipeStep([&#39;recipe_id&#39; =&gt; $recipeId, &#39;desc&#39; =&gt; $step[&#39;desc&#39;]]); });</pre><h3>Example 3</h3><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/How-I-refactor-to-collections"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9c40313aa2e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[PHP 7 performance improvements (3/5): Encapsed strings optimization]]></title>
            <link>https://medium.com/@laravelfeed/php-7-performance-improvements-3-5-encapsed-strings-optimization-599a634cec6f?source=rss-f737c1bdd1dc------2</link>
            <guid isPermaLink="false">https://medium.com/p/599a634cec6f</guid>
            <category><![CDATA[php7]]></category>
            <category><![CDATA[tutorial]]></category>
            <category><![CDATA[php]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[programming]]></category>
            <dc:creator><![CDATA[LaravelFeed]]></dc:creator>
            <pubDate>Tue, 29 Nov 2016 11:35:15 GMT</pubDate>
            <atom:updated>2016-11-29T11:35:15.341Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/0*Rq68iABqZtoja8NX." /></figure><p><a href="http://laravelfeed.com/blog/php-7-performance-improvements-encapsed-strings-optimization#">PHP 7 performance improvements (3/5): Encapsed strings optimization</a></p><p>2 minutes ago</p><p>Julien Pauli, PHP contributor and release manager, details what changed between PHP 5 and PHP 7, and how to migrate and make effective use of the language optimizations. All statements are documented with specific examples and Blackfire profiles. Third episode: Encapsed strings optimization dropping CPU usage by a factor of 10.</p><blockquote><em>The following is the 2nd episode of our blog series on PHP 7 performance improvements, detailed by Julien Pauli PHP Contributor and Release Manager. We will update this introduction with links to all other articles when they are published.</em></blockquote><blockquote><em>Read episode 1: </em><a href="https://blog.blackfire.io/php-7-performance-improvements-packed-arrays.html?utm_source=laravelfeed.com"><em>Packed arrays</em></a></blockquote><blockquote><em>Read episode 2: </em><a href="https://blog.blackfire.io/php-7-performance-improvements-25-intsfloats-are-free-in-php-7.html?utm_source=laravelfeed.com"><em>ints/floats are free in PHP 7</em></a></blockquote><p>Encapsed strings are strings where in-variable scan occur. Those are strings declared using double-quotes or the Heredoc syntax. The algorithm needs to analyze the string, and separate each string part from the variable part. Consider this example :</p><pre>$a = &#39;foo&#39;; $b = &#39;bar&#39;; $c = &quot;I like $a and $b&quot;;</pre><p>When analyzing the $c string, the engine must run so that at the end, $c contains the “I like foo and bar” string. This process has been optimized in PHP 7 as well.</p><p>Here what PHP5 does:</p><p><em>Originally published at </em><a href="http://laravelfeed.com/blog/php-7-performance-improvements-encapsed-strings-optimization"><em>laravelfeed.com</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=599a634cec6f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>