<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: David Lartey</title>
    <description>The latest articles on DEV Community by David Lartey (@dbilovd).</description>
    <link>https://dev.to/dbilovd</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F36390%2F1d557b2c-cab4-47b2-9b4d-f0c455d32866.jpg</url>
      <title>DEV Community: David Lartey</title>
      <link>https://dev.to/dbilovd</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/dbilovd"/>
    <language>en</language>
    <item>
      <title>Dynamic Config Values for Each PHPUnit Test Case in Laravel</title>
      <dc:creator>David Lartey</dc:creator>
      <pubDate>Fri, 15 Feb 2019 13:11:28 +0000</pubDate>
      <link>https://dev.to/dbilovd/dynamic-config-values-for-each-phpunit-test-case-in-laravel-402g</link>
      <guid>https://dev.to/dbilovd/dynamic-config-values-for-each-phpunit-test-case-in-laravel-402g</guid>
      <description>&lt;p&gt;&lt;em&gt;This was originally posted on my &lt;a href="http://dbilovd-blog.herokuapp.com/dynamic-config-phpunit-laravel"&gt;blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Problem:
&lt;/h3&gt;

&lt;p&gt;I am currently working on a USSD application that supports switching between different gateway providers at runtime by changing a configuration value.&lt;/p&gt;

&lt;p&gt;Testing each provider test case was simple and straight forward.  I would update the value in my phpunit.xml file and off I go. However, I ran into problems when I wanted to run my entire test suite.&lt;/p&gt;

&lt;h3&gt;
  
  
  Solution:
&lt;/h3&gt;

&lt;p&gt;It turns out the solution is quite a simple one: Facades. Laravel allows one to mock any Facade when writing your tests. The documentation however, discourages from mocking the Config facade. Instead one should use the Config::set method. &lt;/p&gt;

&lt;p&gt;So, I did something along the lines of the code below.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php
// define your namespace and dependencies here

use Illuminate\Support\Facades\Config;

class GatewayProviderOneTest extends TestCase
{
    public function setUp ()
    {
        parent::setUp();
        Config::set("defaultGatewayProvider", "firstProvider");
    }

    // ... your test methods come here
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s all I needed. Now GatewayProviderOneTest will run its assertions against the value set as the defaultGatewayProvider: firstProvider.&lt;/p&gt;

&lt;p&gt;Additionally, you can revert this to a default value every time in your tearDown method. I however didn’t need to do this. &lt;/p&gt;

</description>
      <category>phpunit</category>
      <category>laravel</category>
      <category>tdd</category>
      <category>php</category>
    </item>
  </channel>
</rss>
