diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml
index a8fce28..fb2831a 100644
--- a/.github/workflows/php.yml
+++ b/.github/workflows/php.yml
@@ -1,39 +1,32 @@
-name: boilerplate build
+name: "ci build"
on:
- push:
- branches:
- - master
pull_request:
- branches:
- - master
+ push:
+ branches:
+ - "master"
jobs:
build:
-
+ name: PHP ${{ matrix.php-versions }}
runs-on: ubuntu-latest
-
+ if: "!contains(github.event.head_commit.message, '[ci skip]')"
+ strategy:
+ fail-fast: false
+ matrix:
+ php-versions: ['7.3', '7.4']
steps:
- - name: Setup PHP
- uses: shivammathur/setup-php@master
- with:
- php-version: '7.2'
- extension-csv: intl, json, mbstring, mysqlnd. xdebug, xml
- coverage: xdebug
- - name: Shutdown Ubuntu MySQL (SUDO)
- run: sudo service mysql stop
- - name: Setup MySQL
- uses: samin/mysql-action@v1.3
- with:
- mysql version: 5.7
- mysql password: test
- mysql user: test
- mysql database: boilerplate-test
- - name: Checkout
- uses: actions/checkout@v2
- - name: "Validate composer.json and composer.lock"
- run: "composer validate"
- - name: "Install dependencies"
- run: "composer install"
- - name: "Run test suite"
- run: "composer test -- -c phpunit.xml.github-actions.dist"
+ - name: Setup PHP Action
+ uses: shivammathur/setup-php@v2
+ with:
+ extensions: intl, json, mbstring, xdebug, xml
+ php-version: "${{ matrix.php-versions }}"
+ coverage: xdebug
+ - name: Checkout
+ uses: actions/checkout@v2
+ - name: "Validate composer.json and composer.lock"
+ run: "composer validate"
+ - name: "Install dependencies"
+ run: "composer install --prefer-source --no-progress --no-suggest"
+ - name: "Run test suite"
+ run: "composer test"
\ No newline at end of file
diff --git a/composer.json b/composer.json
index c567abb..ce8a810 100644
--- a/composer.json
+++ b/composer.json
@@ -16,14 +16,14 @@
}
],
"require": {
- "php": ">7.2",
+ "php": "^7.3 || ^8.0",
"myth/auth": "dev-develop",
+ "codeigniter4/framework": "^4.1",
"codeigniter4/translations" : "^4.0"
},
"require-dev": {
- "codeigniter4/framework": "^4.0",
- "phpunit/phpunit": "8.5.*",
- "fakerphp/faker": "^1.10"
+ "phpunit/phpunit": "^9.1",
+ "fakerphp/faker": "^1.13"
},
"minimum-stability": "dev",
"prefer-stable": true,
diff --git a/phpunit.xml.dist b/phpunit.xml.dist
index b74bf33..e1a2fc8 100644
--- a/phpunit.xml.dist
+++ b/phpunit.xml.dist
@@ -42,11 +42,7 @@
-
-
-
-
-
-
+
+
\ No newline at end of file
diff --git a/phpunit.xml.github-actions.dist b/phpunit.xml.github-actions.dist
deleted file mode 100644
index 23465e5..0000000
--- a/phpunit.xml.github-actions.dist
+++ /dev/null
@@ -1,52 +0,0 @@
-
-
-
-
- ./tests
-
-
-
-
-
- ./src
-
- ./src/Database
- ./src/Views
- ./src/Config
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/tests/Controllers/ExampleTest.php b/tests/Controllers/ExampleTest.php
index 5190043..50de67d 100644
--- a/tests/Controllers/ExampleTest.php
+++ b/tests/Controllers/ExampleTest.php
@@ -1,20 +1,20 @@
-controller(Home::class)
- ->execute('index');
-
- $this->assertTrue($result->isOK());
- }
-}
\ No newline at end of file
+controller(Home::class)
+ ->execute('index');
+
+ $this->assertTrue($result->isOK());
+ }
+}
diff --git a/tests/Support/AuthTestCase.php b/tests/Support/AuthTestCase.php
index 08f910a..431a3d1 100644
--- a/tests/Support/AuthTestCase.php
+++ b/tests/Support/AuthTestCase.php
@@ -1,112 +1,111 @@
-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' => 'fred@example.com',
- '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' => 'fred@example.com',
+ '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);
diff --git a/tests/Support/SessionTestCase.php b/tests/Support/SessionTestCase.php
index 9f1925e..2f8b521 100644
--- a/tests/Support/SessionTestCase.php
+++ b/tests/Support/SessionTestCase.php
@@ -1,4 +1,4 @@
-mockSession();
}
-
+
/**
* Pre-loads the mock session driver into $this->session.
*
@@ -26,7 +26,7 @@ public function setUp(): void
*/
protected function mockSession()
{
- require_once SYSTEMPATH . 'Test/Mock/MockSession.php';
+ 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);
diff --git a/tests/UserTest.php b/tests/UserTest.php
index 0c8476a..c4b045c 100644
--- a/tests/UserTest.php
+++ b/tests/UserTest.php
@@ -11,13 +11,13 @@ public function testGetPermissionsThroughUser()
$permission2 = $this->createPermission(['name' => 'second']);
$this->hasInDatabase('auth_users_permissions', [
- 'user_id' => $user->id,
- 'permission_id' => $permission1->id
+ 'user_id' => $user->id,
+ 'permission_id' => $permission1->id,
]);
$this->hasInDatabase('auth_users_permissions', [
- 'user_id' => $user->id,
- 'permission_id' => $permission2->id
+ 'user_id' => $user->id,
+ 'permission_id' => $permission2->id,
]);
$expected = [
@@ -35,13 +35,13 @@ public function testGetPermissionsThroughGroup()
$permission = $this->createPermission(['name' => 'first']);
$this->hasInDatabase('auth_groups_permissions', [
- 'group_id' => $group->id,
- 'permission_id' => $permission->id
+ 'group_id' => $group->id,
+ 'permission_id' => $permission->id,
]);
$this->hasInDatabase('auth_groups_users', [
- 'user_id' => $user->id,
- 'group_id' => $group->id
+ 'user_id' => $user->id,
+ 'group_id' => $group->id,
]);
$expected = [
@@ -56,8 +56,8 @@ public function testCan()
$user = $this->createUser();
$permission = $this->createPermission();
$this->hasInDatabase('auth_users_permissions', [
- 'user_id' => $user->id,
- 'permission_id' => $permission->id
+ 'user_id' => $user->id,
+ 'permission_id' => $permission->id,
]);
$this->assertTrue($user->can($permission->name));