From baaad3eb9992914b84de74ee24e5298de99cc4ef Mon Sep 17 00:00:00 2001 From: Agung Sugiarto Date: Mon, 1 Feb 2021 17:57:30 +0700 Subject: [PATCH 1/6] upgrade codeigniter to last version --- .github/workflows/php.yml | 2 +- composer.json | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index a8fce28..507a7f2 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -34,6 +34,6 @@ jobs: - name: "Validate composer.json and composer.lock" run: "composer validate" - name: "Install dependencies" - run: "composer install" + run: "composer install --prefer-source --no-progress --no-suggest" - name: "Run test suite" run: "composer test -- -c phpunit.xml.github-actions.dist" 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, From 07cc6707b3be4d00a5106e7a1037ca9ee8debcec Mon Sep 17 00:00:00 2001 From: Agung Sugiarto Date: Mon, 1 Feb 2021 10:57:54 +0000 Subject: [PATCH 2/6] Apply fixes from StyleCI --- tests/Controllers/ExampleTest.php | 40 +++---- tests/Support/AuthTestCase.php | 179 +++++++++++++++--------------- tests/Support/SessionTestCase.php | 6 +- tests/UserTest.php | 20 ++-- 4 files changed, 122 insertions(+), 123 deletions(-) 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)); From 0faa14cdc5277697b9081c123e2c293637623f89 Mon Sep 17 00:00:00 2001 From: Agung Sugiarto Date: Mon, 1 Feb 2021 18:05:28 +0700 Subject: [PATCH 3/6] update version php on ci --- .github/workflows/php.yml | 54 ++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 507a7f2..1713534 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,39 +1,41 @@ -name: boilerplate build +name: "Boilerplate 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 + - name: Setup PHP Action + uses: shivammathur/setup-php@v2 + with: + extensions: intl, json, mbstring, xdebug, xml + php-version: "${{ matrix.php-versions }}" + 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 --prefer-source --no-progress --no-suggest" - - name: "Run test suite" - run: "composer test -- -c phpunit.xml.github-actions.dist" + - 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 From 701331d1e21993811d7f0a576fde8cb5ee578403 Mon Sep 17 00:00:00 2001 From: Agung Sugiarto Date: Mon, 1 Feb 2021 18:10:15 +0700 Subject: [PATCH 4/6] update php.yml --- .github/workflows/php.yml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 1713534..05faf5d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -26,11 +26,11 @@ jobs: 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 + 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" From e1b1d5631c33e1cc029c96196df9166fb22f74e7 Mon Sep 17 00:00:00 2001 From: Agung Sugiarto Date: Mon, 1 Feb 2021 18:17:14 +0700 Subject: [PATCH 5/6] update user & password phpunit --- phpunit.xml.dist | 4 +-- phpunit.xml.github-actions.dist | 52 --------------------------------- 2 files changed, 2 insertions(+), 54 deletions(-) delete mode 100644 phpunit.xml.github-actions.dist diff --git a/phpunit.xml.dist b/phpunit.xml.dist index b74bf33..5add90b 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -44,8 +44,8 @@ - - + + 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 From c7c38f6cd23c29b7ed857eed13be77c1a3f09238 Mon Sep 17 00:00:00 2001 From: Agung Sugiarto Date: Mon, 1 Feb 2021 18:26:38 +0700 Subject: [PATCH 6/6] change with sqlite3 --- .github/workflows/php.yml | 11 +---------- phpunit.xml.dist | 8 ++------ 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 05faf5d..fb2831a 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -1,4 +1,4 @@ -name: "Boilerplate Build" +name: "ci build" on: pull_request: @@ -22,15 +22,6 @@ jobs: extensions: intl, json, mbstring, xdebug, xml php-version: "${{ matrix.php-versions }}" 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" diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 5add90b..e1a2fc8 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -42,11 +42,7 @@ - - - - - - + + \ No newline at end of file