Skip to content

Commit

Permalink
Added config copy to Setup script
Browse files Browse the repository at this point in the history
Signed-off-by: tswagger <tim@renowne.com>
  • Loading branch information
tswagger committed Sep 18, 2023
1 parent 968997a commit a1b64db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Commands/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ private function publishConfig(): void
{
$this->publishConfigAuth();
$this->publishConfigAuthGroups();
$this->publishConfigAuthToken();

$this->setupHelper();
$this->setupRoutes();
Expand Down Expand Up @@ -131,6 +132,18 @@ private function publishConfigAuthGroups(): void
$this->copyAndReplace($file, $replaces);
}

private function publishConfigAuthToken(): void
{
$file = 'Config/AuthToken.php';
$replaces = [
'namespace CodeIgniter\Shield\Config' => 'namespace Config',
'use CodeIgniter\\Config\\BaseConfig;' => 'use CodeIgniter\\Shield\\Config\\AuthToken as ShieldAuthToken;',
'extends BaseConfig' => 'extends ShieldAuthToken',
];

$this->copyAndReplace($file, $replaces);
}

/**
* Write a file, catching any exceptions and showing a
* nicely formatted error.
Expand Down
5 changes: 5 additions & 0 deletions tests/Commands/SetupTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ public function testRun(): void
$this->assertStringContainsString('namespace Config;', $auth);
$this->assertStringContainsString('use CodeIgniter\Shield\Config\Auth as ShieldAuth;', $auth);

$authToken = file_get_contents($appFolder . 'Config/AuthToken.php');
$this->assertStringContainsString('namespace Config;', $authToken);
$this->assertStringContainsString('use CodeIgniter\Shield\Config\AuthToken as ShieldAuthToken;', $authToken);

$routes = file_get_contents($appFolder . 'Config/Routes.php');
$this->assertStringContainsString('service(\'auth\')->routes($routes);', $routes);

Expand All @@ -79,6 +83,7 @@ public function testRun(): void
$this->assertStringContainsString(
' Created: vfs://root/Config/Auth.php
Created: vfs://root/Config/AuthGroups.php
Created: vfs://root/Config/AuthToken.php
Updated: vfs://root/Controllers/BaseController.php
Updated: vfs://root/Config/Routes.php
Updated: We have updated file \'vfs://root/Config/Security.php\' for security reasons.',
Expand Down

0 comments on commit a1b64db

Please sign in to comment.