Skip to content

Commit

Permalink
Merge pull request #9 from samsonasik/support-php73-php80
Browse files Browse the repository at this point in the history
[Deps] Support php ^7.3 || ^8.0
  • Loading branch information
samsonasik authored May 20, 2021
2 parents ac5d31f + d55faa9 commit a2be792
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 85 deletions.
10 changes: 5 additions & 5 deletions .github/workflows/ci_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ jobs:
strategy:
fail-fast: false
matrix:
php-versions: ['7.2', '7.3', '7.4']
php-versions: ['7.3', '7.4', '8.0']
steps:
- name: Setup PHP Action
uses: shivammathur/setup-php@1.8.2
uses: shivammathur/setup-php@v2
with:
extensions: intl
php-version: "${{ matrix.php-versions }}"
coverage: pcov
coverage: xdebug
- name: Shutdown Ubuntu MySQL (SUDO)
run: sudo service mysql stop
- name: Setup MySQL
Expand Down Expand Up @@ -50,7 +50,7 @@ jobs:
run: |
composer require --dev infection/infection
vendor/bin/infection
- if: matrix.php-versions == '7.2'
- if: matrix.php-versions == '7.3'
name: Upload coverage to Codecov
uses: codecov/codecov-action@v1
with:
Expand All @@ -59,4 +59,4 @@ jobs:
flags: tests
name: codecov-umbrella
yml: ./codecov.yml
fail_ci_if_error: true
fail_ci_if_error: true
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
}
],
"require": {
"php": "^7.2"
"php": "^7.3 || ^8.0"
},
"require-dev": {
"codeigniter4/codeigniter4-standard": "^1.0.1",
"codeigniter4/framework": "^4.0.3",
"codeigniter4/framework": "^4.1",
"phpstan/phpstan": "^0.12.14",
"phpunit/phpunit": "^8",
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "^3.1"
},
"config": {
Expand Down
4 changes: 2 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ includes:
- vendor/phpstan/phpstan/conf/bleedingEdge.neon

parameters:
bootstrap: bootstrap.php
bootstrapFiles:
- bootstrap.php
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
excludes_analyse:
Expand All @@ -15,4 +16,3 @@ parameters:
- '#Call to an undefined static method Config\\Services::albumRepository\(\)#'
- '#Call to an undefined static method Config\\Services::trackRepository\(\)#'
- '#Call to an undefined static method Config\\Services::albumTrackSummary\(\)#'
- '#Call to protected method builder\(\) of class CodeIgniter\\Model.#'
3 changes: 3 additions & 0 deletions src/Controllers/Album.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@

class Album extends BaseController
{
/** @var \CodeIgniter\HTTP\IncomingRequest */
protected $request;

/** @var AlbumRepository */
private $repository;

Expand Down
3 changes: 3 additions & 0 deletions src/Controllers/Track.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@

class Track extends BaseController
{
/** @var \CodeIgniter\HTTP\IncomingRequest */
protected $request;

/** @var AlbumRepository */
private $albumRepository;

Expand Down
10 changes: 9 additions & 1 deletion src/Infrastructure/Persistence/DMLPersistence.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Album\Infrastructure\Persistence;

use CodeIgniter\Database\Exceptions\DataException;
use CodeIgniter\Model;

/**
Expand All @@ -10,6 +11,13 @@ trait DMLPersistence
{
public function save(array $data = null): bool
{
return $this->model instanceof Model && $this->model->save(new $this->model->returnType($data));
try
{
return $this->model instanceof Model && $this->model->save(new $this->model->returnType($data));
}
catch (DataException $e)
{
return false;
}
}
}
50 changes: 17 additions & 33 deletions test/Controller/AlbumTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@

use Album\Controllers\Album;
use Album\Database\Seeds\AlbumSeeder;
use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\ControllerTester;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\ControllerTestTrait;
use CodeIgniter\Test\DatabaseTestTrait;
use Config\Database;
use Config\Services;

/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class AlbumTest extends CIDatabaseTestCase
class AlbumTest extends CIUnitTestCase
{
use ControllerTester;
use DatabaseTestTrait, ControllerTestTrait;

protected $basePath = __DIR__ . '/../src/Database/';
protected $namespace = 'Album';
Expand Down Expand Up @@ -44,7 +45,7 @@ public function testIndexAlbumHasData()
public function testIndexSearchAlbumFound()
{
$request = Services::request();
$request->setMethod('get');
$request = $request->withMethod('get');
$request->setGlobal('get', [
'keyword' => 'Sheila',
]);
Expand All @@ -59,7 +60,7 @@ public function testIndexSearchAlbumFound()
public function testIndexSearchAlbumNotFound()
{
$request = Services::request();
$request->setMethod('get');
$request = $request->withMethod('get');
$request->setGlobal('get', [
'keyword' => 'Siti',
]);
Expand All @@ -82,28 +83,19 @@ public function testAddAlbum()
public function testAddAlbumInvalidData()
{
$request = Services::request(null, false);
$request->setMethod('post');
$request = $request->withMethod('post');

$result = $this->withRequest($request)
->controller(Album::class)
->execute('add');
$this->assertTrue($result->isRedirect());
$this->withRequest($request)
->controller(Album::class)
->execute('add');

$request = Services::request(null, false);
$request->setMethod('get');

$result = $this->withRequest($request)
->controller(Album::class)
->execute('add');
$this->assertTrue($result->isOK());
$this->assertTrue($result->see('The artist field is required.'));
$this->assertTrue($result->see('The title field is required.'));
$this->seeNumRecords(1, 'album', []);
}

public function testAddAlbumValidData()
{
$request = Services::request();
$request->setMethod('post');
$request = $request->withMethod('post');
$request->setGlobal('post', [
'artist' => 'Siti Nurhaliza',
'title' => 'Anugrah Aidilfitri',
Expand Down Expand Up @@ -135,28 +127,19 @@ public function testEditExistenceAlbum()
public function testEditAlbumInvalidData()
{
$request = Services::request(null, false);
$request->setMethod('post');
$request = $request->withMethod('post');

$result = $this->withRequest($request)
->controller(Album::class)
->execute('edit', 1);
$this->assertTrue($result->isRedirect());

$request = Services::request(null, false);
$request->setMethod('get');

$result = $this->withRequest($request)
->controller(Album::class)
->execute('edit', 1);
$this->assertTrue($result->isOK());
$this->assertTrue($result->see('The artist field is required.'));
$this->assertTrue($result->see('The title field is required.'));
$this->assertNotEquals('http://localhost:8080/index.php/album', $result->getRedirectUrl());
}

public function testEditAlbumValidData()
{
$request = Services::request();
$request->setMethod('post');
$request = $request->withMethod('post');
$request->setGlobal('post', [
'id' => 1,
'artist' => 'Siti Nurhaliza',
Expand All @@ -168,6 +151,7 @@ public function testEditAlbumValidData()
->execute('edit', 1);

$this->assertTrue($result->isRedirect());
$this->assertEquals('http://localhost:8080/index.php/album', $result->getRedirectUrl());
}

public function testDeleteUnexistenceAlbum()
Expand Down
15 changes: 10 additions & 5 deletions test/Controller/AlbumTrackSummaryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,18 @@
use Album\Controllers\AlbumTrackSummary;
use Album\Database\Seeds\AlbumSeeder;
use Album\Database\Seeds\TrackSeeder;
use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\ControllerTester;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\ControllerTestTrait;
use CodeIgniter\Test\DatabaseTestTrait;
use Config\Database;

class AlbumTrackSummaryTest extends CIDatabaseTestCase
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class AlbumTrackSummaryTest extends CIUnitTestCase
{
use ControllerTester;
use ControllerTestTrait, DatabaseTestTrait;

protected $basePath = __DIR__ . '/../src/Database/';
protected $namespace = 'Album';
Expand Down Expand Up @@ -37,6 +42,6 @@ public function testTotalSongSummaryHasData()
->execute('totalsong');

$this->assertTrue($result->isOK());
$this->assertRegExp('/Sheila On 7<\/td>\s{0,}\n\s{0,}<td>1<\/td>/', $result->getBody());
$this->assertMatchesRegularExpression('/Sheila On 7<\/td>\s{0,}\n\s{0,}<td>1<\/td>/', $result->getBody());
}
}
44 changes: 14 additions & 30 deletions test/Controller/TrackTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,19 @@
use Album\Controllers\Track;
use Album\Database\Seeds\AlbumSeeder;
use Album\Database\Seeds\TrackSeeder;
use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\ControllerTester;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\ControllerTestTrait;
use CodeIgniter\Test\DatabaseTestTrait;
use Config\Database;
use Config\Services;

/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
class TrackTest extends CIDatabaseTestCase
class TrackTest extends CIUnitTestCase
{
use ControllerTester;
use DatabaseTestTrait, ControllerTestTrait;

protected $basePath = __DIR__ . '/../src/Database/';
protected $namespace = 'Album';
Expand Down Expand Up @@ -56,7 +57,7 @@ public function testIndexTrackHasData()
public function testIndexSearchTrackFound()
{
$request = Services::request();
$request->setMethod('get');
$request = $request->withMethod('get');
$request->setGlobal('get', [
'keyword' => 'kisah',
]);
Expand All @@ -71,7 +72,7 @@ public function testIndexSearchTrackFound()
public function testIndexSearchTrackNotFound()
{
$request = Services::request();
$request->setMethod('get');
$request = $request->withMethod('get');
$request->setGlobal('get', [
'keyword' => 'Purnama',
]);
Expand Down Expand Up @@ -102,28 +103,19 @@ public function testAddTrack()
public function testAddTrackInvalidData()
{
$request = Services::request(null, false);
$request->setMethod('post');
$request = $request->withMethod('post');

$result = $this->withRequest($request)
->controller(Track::class)
->execute('add', 1);
$this->assertTrue($result->isRedirect());

$request = Services::request(null, false);
$request->setMethod('get');

$result = $this->withRequest($request)
->controller(Track::class)
->execute('add', 1);
$this->assertTrue($result->isOK());
$this->assertTrue($result->see('The title field is required.'));
$this->assertTrue($result->see('The author field is required.'));
$this->seeNumRecords(1, 'track', []);
}

public function testAddTrackValidData()
{
$request = Services::request();
$request->setMethod('post');
$request = $request->withMethod('post');
$request->setGlobal('post', [
'album_id' => 1,
'title' => 'Sahabat Sejati',
Expand Down Expand Up @@ -156,28 +148,19 @@ public function testEditExistenceTrack()
public function testEditTrackInvalidData()
{
$request = Services::request(null, false);
$request->setMethod('post');
$request = $request->withMethod('post');

$result = $this->withRequest($request)
->controller(Track::class)
->execute('edit', 1, 1);
$this->assertTrue($result->isRedirect());

$request = Services::request(null, false);
$request->setMethod('get');

$result = $this->withRequest($request)
->controller(Track::class)
->execute('edit', 1, 1);
$this->assertTrue($result->isOK());
$this->assertTrue($result->see('The title field is required.'));
$this->assertTrue($result->see('The author field is required.'));
$this->assertNotEquals('http://localhost:8080/index.php/album-track/1', $result->getRedirectUrl());
}

public function testEditTrackValidData()
{
$request = Services::request();
$request->setMethod('post');
$request = $request->withMethod('post');
$request->setGlobal('post', [
'id' => 1,
'album_id' => 1,
Expand All @@ -190,6 +173,7 @@ public function testEditTrackValidData()
->execute('edit', 1, 1);

$this->assertTrue($result->isRedirect());
$this->assertEquals('http://localhost:8080/index.php/album-track/1', $result->getRedirectUrl());
}

public function testDeleteUnexistenceTrack()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
use Album\Database\Seeds\AlbumSeeder;
use Album\Domain\Album\Album;
use Album\Domain\Album\AlbumNotFoundException;
use CodeIgniter\Test\CIDatabaseTestCase;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Config\Services;

class SQLAlbumRepositoryTest extends CIDatabaseTestCase
class SQLAlbumRepositoryTest extends CIUnitTestCase
{
use DatabaseTestTrait;

protected $basePath = __DIR__ . '/../src/Database/';
protected $namespace = 'Album';
protected $seed = AlbumSeeder::class;
Expand Down
Loading

0 comments on commit a2be792

Please sign in to comment.