Skip to content

Commit e52bec8

Browse files
authored
Merge pull request #41 from tattersoftware/config
Test Config
2 parents b4bc529 + 3b5abec commit e52bec8

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed

src/Asset.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Tatter\Assets;
44

5+
use CodeIgniter\Config\Factories;
56
use CodeIgniter\Files\File;
67
use Tatter\Assets\Config\Assets as AssetsConfig;
78
use Tatter\Assets\Exceptions\AssetsException;
@@ -76,6 +77,9 @@ public static function config(): AssetsConfig
7677
public static function useConfig(?AssetsConfig $config)
7778
{
7879
self::$config = $config;
80+
81+
// If a new config was supplied then use it with Factories, otherwise reset to the "vanilla" version
82+
Factories::injectMock('config', 'Assets', $config ?? new AssetsConfig());
7983
}
8084

8185
//--------------------------------------------------------------------

src/Test/AssetsTestTrait.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function setUpAssetsTestTrait(): void
4545
}
4646

4747
// Create the config
48-
$this->config = config('Assets');
48+
$this->config = new AssetsConfig();
4949
$this->config->directory = $this->root->url() . DIRECTORY_SEPARATOR;
5050
$this->config->useTimestamps = false; // These make testing much harder
5151

@@ -64,6 +64,8 @@ protected function tearDownAssetsTestTrait(): void
6464
$this->root = null;
6565
$this->published = false;
6666
}
67+
68+
Asset::useConfig(null);
6769
}
6870

6971
/**

tests/AssetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public function testUsesConfig()
3434
$result = Asset::config();
3535

3636
$this->assertSame($config, $result);
37-
$this->assertNotSame(config(AssetsConfig::class), $result);
37+
$this->assertSame(config(AssetsConfig::class), $result);
3838
}
3939

4040
public function testLoadsConfig()

0 commit comments

Comments
 (0)