-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
173 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* This file is part of CodeIgniter 4 framework. | ||
* | ||
* (c) CodeIgniter Foundation <[email protected]> | ||
* | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
*/ | ||
|
||
namespace CodeIgniter\Commands\Utilities; | ||
|
||
use CodeIgniter\Test\CIUnitTestCase; | ||
use CodeIgniter\Test\StreamFilterTrait; | ||
use PHPUnit\Framework\Attributes\Group; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
#[Group('Others')] | ||
final class OptimizeTest extends CIUnitTestCase | ||
{ | ||
use StreamFilterTrait; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->resetServices(); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
protected function getBuffer(): string | ||
{ | ||
return $this->getStreamFilterBuffer(); | ||
} | ||
|
||
public function testEnableConfigCaching(): void | ||
{ | ||
$command = new Optimize(service('logger'), service('commands')); | ||
|
||
$enableCaching = $this->getPrivateMethodInvoker($command, 'enableCaching'); | ||
|
||
// private function enableCaching(?bool $enableConfigCache, ?bool $enableLocatorCache, ?bool $disable): void | ||
$enableCaching(true, null, null); | ||
|
||
// Check if config caching is enabled | ||
$this->assertFileContains('public bool $configCacheEnabled = true;', APPPATH . 'Config/Optimize.php'); | ||
} | ||
|
||
public function testEnableLocatorCaching(): void | ||
{ | ||
$command = new Optimize(service('logger'), service('commands')); | ||
|
||
$enableCaching = $this->getPrivateMethodInvoker($command, 'enableCaching'); | ||
|
||
// private function enableCaching(?bool $enableConfigCache, ?bool $enableLocatorCache, ?bool $disable): void | ||
$enableCaching(null, true, null); | ||
|
||
// Check if locator caching is enabled | ||
$this->assertFileContains('public bool $locatorCacheEnabled = true;', APPPATH . 'Config/Optimize.php'); | ||
} | ||
|
||
public function testDisableCaching(): void | ||
{ | ||
$command = new Optimize(service('logger'), service('commands')); | ||
|
||
$enableCaching = $this->getPrivateMethodInvoker($command, 'enableCaching'); | ||
|
||
// private function enableCaching(?bool $enableConfigCache, ?bool $enableLocatorCache, ?bool $disable): void | ||
$enableCaching(null, null, true); | ||
|
||
// Check if both caches are disabled | ||
$this->assertFileContains('public bool $configCacheEnabled = false;', APPPATH . 'Config/Optimize.php'); | ||
$this->assertFileContains('public bool $locatorCacheEnabled = false;', APPPATH . 'Config/Optimize.php'); | ||
} | ||
|
||
public function testWithoutOptions(): void | ||
{ | ||
$command = new Optimize(service('logger'), service('commands')); | ||
|
||
$enableCaching = $this->getPrivateMethodInvoker($command, 'enableCaching'); | ||
|
||
// private function enableCaching(?bool $enableConfigCache, ?bool $enableLocatorCache, ?bool $disable): void | ||
$enableCaching(null, null, null); | ||
|
||
// Check if both caches are disabled | ||
$this->assertFileContains('public bool $configCacheEnabled = true;', APPPATH . 'Config/Optimize.php'); | ||
$this->assertFileContains('public bool $locatorCacheEnabled = true;', APPPATH . 'Config/Optimize.php'); | ||
} | ||
|
||
protected function assertFileContains(string $needle, string $filePath): void | ||
{ | ||
$this->assertFileExists($filePath); | ||
$this->assertStringContainsString($needle, file_get_contents($filePath)); | ||
} | ||
} |