forked from agungsugiarto/boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
baaad3e
commit 07cc670
Showing
4 changed files
with
122 additions
and
123 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,20 @@ | ||
<?php | ||
|
||
namespace Tests\Controllers; | ||
|
||
use App\Controllers\Home; | ||
use CodeIgniter\Test\ControllerTester; | ||
use Tests\Support\AuthTestCase; | ||
|
||
class ExampleTest extends AuthTestCase | ||
{ | ||
use ControllerTester; | ||
public function testIndexHome() | ||
{ | ||
$result = $this->controller(Home::class) | ||
->execute('index'); | ||
$this->assertTrue($result->isOK()); | ||
} | ||
} | ||
<?php | ||
|
||
namespace Tests\Controllers; | ||
|
||
use App\Controllers\Home; | ||
use CodeIgniter\Test\ControllerTester; | ||
use Tests\Support\AuthTestCase; | ||
|
||
class ExampleTest extends AuthTestCase | ||
{ | ||
use ControllerTester; | ||
|
||
public function testIndexHome() | ||
{ | ||
$result = $this->controller(Home::class) | ||
->execute('index'); | ||
|
||
$this->assertTrue($result->isOK()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,112 +1,111 @@ | ||
<?php | ||
<?php | ||
|
||
namespace Tests\Support; | ||
|
||
use CodeIgniter\Test\ControllerTester; | ||
use CodeIgniter\Session\Handlers\ArrayHandler; | ||
use CodeIgniter\Test\Mock\MockSession; | ||
use CodeIgniter\Test\CIDatabaseTestCase; | ||
use CodeIgniter\Test\ControllerTester; | ||
use CodeIgniter\Test\Mock\MockSession; | ||
use Myth\Auth\Entities\User; | ||
use Myth\Auth\Models\UserModel; | ||
|
||
class AuthTestCase extends CIDatabaseTestCase | ||
{ | ||
use ControllerTester; | ||
|
||
/** | ||
* Should the database be refreshed before each test? | ||
* | ||
* @var boolean | ||
*/ | ||
protected $refresh = true; | ||
|
||
/** | ||
* The name of a seed file used for all tests within this test case. | ||
* | ||
* @var string | ||
*/ | ||
protected $seed = 'agungsugiarto\boilerplate\Database\Seeds\BoilerplateSeeder'; | ||
|
||
/** | ||
* The namespace to help us find the migration classes. | ||
* | ||
* @var string | ||
*/ | ||
protected $namespace = ['Myth\Auth', 'agungsugiarto\boilerplate']; | ||
|
||
/** | ||
* @var \Myth\Auth\Models\UserModel | ||
*/ | ||
protected $users; | ||
|
||
protected $faker; | ||
|
||
/** | ||
* @var SessionHandler | ||
*/ | ||
protected $session; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->users = new UserModel(); | ||
$this->mockSession(); | ||
|
||
$this->faker = \Faker\Factory::create(); | ||
} | ||
|
||
/** | ||
* Pre-loads the mock session driver into $this->session. | ||
* | ||
*/ | ||
protected function mockSession() | ||
{ | ||
require_once SYSTEMPATH . 'Test/Mock/MockSession.php'; | ||
$config = config('App'); | ||
$this->session = new MockSession(new ArrayHandler($config, '0.0.0.0'), $config); | ||
\Config\Services::injectMock('session', $this->session); | ||
$_SESSION = []; | ||
} | ||
|
||
/** | ||
* Creates a user on-the-fly. | ||
* | ||
* @param string $reason | ||
* | ||
* @return $this | ||
*/ | ||
protected function createUser(array $info = []) | ||
{ | ||
$defaults = [ | ||
'email' => '[email protected]', | ||
'username' => 'Fred', | ||
'password' => 'secret' | ||
]; | ||
$info = array_merge($info, $defaults); | ||
$user = new User($info); | ||
|
||
$userId = $this->users->insert($user); | ||
$user = $this->users->find($userId); | ||
|
||
// Delete any cached permissions | ||
use ControllerTester; | ||
|
||
/** | ||
* Should the database be refreshed before each test? | ||
* | ||
* @var bool | ||
*/ | ||
protected $refresh = true; | ||
|
||
/** | ||
* The name of a seed file used for all tests within this test case. | ||
* | ||
* @var string | ||
*/ | ||
protected $seed = 'agungsugiarto\boilerplate\Database\Seeds\BoilerplateSeeder'; | ||
|
||
/** | ||
* The namespace to help us find the migration classes. | ||
* | ||
* @var string | ||
*/ | ||
protected $namespace = ['Myth\Auth', 'agungsugiarto\boilerplate']; | ||
|
||
/** | ||
* @var \Myth\Auth\Models\UserModel | ||
*/ | ||
protected $users; | ||
|
||
protected $faker; | ||
|
||
/** | ||
* @var SessionHandler | ||
*/ | ||
protected $session; | ||
|
||
public function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->users = new UserModel(); | ||
$this->mockSession(); | ||
|
||
$this->faker = \Faker\Factory::create(); | ||
} | ||
|
||
/** | ||
* Pre-loads the mock session driver into $this->session. | ||
*/ | ||
protected function mockSession() | ||
{ | ||
require_once SYSTEMPATH.'Test/Mock/MockSession.php'; | ||
$config = config('App'); | ||
$this->session = new MockSession(new ArrayHandler($config, '0.0.0.0'), $config); | ||
\Config\Services::injectMock('session', $this->session); | ||
$_SESSION = []; | ||
} | ||
|
||
/** | ||
* Creates a user on-the-fly. | ||
* | ||
* @param string $reason | ||
* | ||
* @return $this | ||
*/ | ||
protected function createUser(array $info = []) | ||
{ | ||
$defaults = [ | ||
'email' => '[email protected]', | ||
'username' => 'Fred', | ||
'password' => 'secret', | ||
]; | ||
$info = array_merge($info, $defaults); | ||
$user = new User($info); | ||
|
||
$userId = $this->users->insert($user); | ||
$user = $this->users->find($userId); | ||
|
||
// Delete any cached permissions | ||
cache()->delete("{$userId}_permissions"); | ||
|
||
return $user; | ||
} | ||
return $user; | ||
} | ||
|
||
/** | ||
* Creates a group on the fly | ||
* Creates a group on the fly. | ||
* | ||
* @param array $info | ||
* | ||
* @return mixed | ||
*/ | ||
protected function createGroup(array $info = []) | ||
protected function createGroup(array $info = []) | ||
{ | ||
$defaults = [ | ||
'name' => $this->faker->word, | ||
'description' => $this->faker->sentence | ||
'name' => $this->faker->word, | ||
'description' => $this->faker->sentence, | ||
]; | ||
$info = array_merge($info, $defaults); | ||
|
||
|
@@ -125,8 +124,8 @@ protected function createGroup(array $info = []) | |
protected function createPermission(array $info = []) | ||
{ | ||
$defaults = [ | ||
'name' => $this->faker->word, | ||
'description' => $this->faker->sentence | ||
'name' => $this->faker->word, | ||
'description' => $this->faker->sentence, | ||
]; | ||
$info = array_merge($info, $defaults); | ||
|
||
|
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