-
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.
Merge pull request #1 from fykosak/dev-tests
Tests
- Loading branch information
Showing
23 changed files
with
1,150 additions
and
9 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 |
---|---|---|
@@ -0,0 +1,49 @@ | ||
name: PHP (Nette Tester) | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
name: PHP ${{ matrix.php }} with ${{ matrix.database }} | ||
runs-on: ubuntu-20.04 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
php: [ '7.4' ] | ||
database: [ 'mysql' ] | ||
steps: | ||
# MariaDB container has to be started in advance to initialize itself before using it. | ||
- uses: actions/checkout@v2 | ||
name: Checkout | ||
with: | ||
submodules: recursive | ||
- uses: shivammathur/setup-php@v2 | ||
name: Setup PHP | ||
with: | ||
php-version: ${{ matrix.php }} | ||
extensions: curl, mbstring, mysql, soap, xml | ||
tools: composer | ||
ini-values: session.gc_probability=0, date.timezone="Europe/Prague", display_startup_errors = Off | ||
- name: Composer install | ||
run: composer install --no-progress --prefer-dist | ||
- name: DB configuration | ||
run: "sed -e 's/user:/user: runner/' tests/config.local.neon.example > tests/config.local.neon" | ||
- name: Start and prepare MySQL | ||
run: | | ||
sudo service mysql start | ||
sudo mysql -proot -e "ALTER USER 'root'@'localhost' IDENTIFIED BY ''; CREATE USER 'runner'@'localhost' IDENTIFIED BY ''; GRANT ALL PRIVILEGES ON * . * TO 'runner'@'localhost';" | ||
- run: composer run-script initTestDatabase | ||
name: Init test database | ||
- run: composer run-script testCoverage | ||
name: Test | ||
- name: Archive code coverage results | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: code-coverage-report | ||
path: coverage.html | ||
- if: failure() | ||
name: Failure output | ||
uses: actions/upload-artifact@v2 | ||
with: | ||
name: output | ||
path: tests/**/*.actual |
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 +1,4 @@ | ||
/vendor/ | ||
/tests/config.local.neon | ||
/tests/temp/* | ||
!/tests/temp/.gitignore |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Fykosak\NetteORM\Tests\ORM; | ||
|
||
use Fykosak\NetteORM\AbstractModel; | ||
|
||
class ModelEvent extends AbstractModel { | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Fykosak\NetteORM\Tests\ORM; | ||
|
||
use Fykosak\NetteORM\AbstractModel; | ||
|
||
class ModelParticipant extends AbstractModel { | ||
|
||
public function getEvent(): ModelEvent { | ||
return ModelEvent::createFromActiveRow($this->event); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Fykosak\NetteORM\Tests\ORM; | ||
|
||
use Fykosak\NetteORM\AbstractService; | ||
|
||
class ServiceEvent extends AbstractService { | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<?php | ||
|
||
namespace Fykosak\NetteORM\Tests\ORM; | ||
|
||
use Fykosak\NetteORM\AbstractService; | ||
|
||
class ServiceParticipant extends AbstractService { | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
namespace Fykosak\NetteORM\Tests\Tests; | ||
|
||
use Fykosak\NetteORM\ORMExtension; | ||
use Nette\Bridges\DatabaseDI\DatabaseExtension; | ||
use Nette\Database\Explorer; | ||
use Nette\DI\Compiler; | ||
use Nette\DI\Container; | ||
use Nette\DI\ContainerLoader; | ||
use Tester\Environment; | ||
use Tester\TestCase; | ||
|
||
define('__TEMP__DIR__', __DIR__ . '/../temp'); | ||
|
||
require_once __DIR__ . '/../../vendor/autoload.php'; | ||
|
||
class AbstractTestCase extends TestCase { | ||
|
||
protected Container $container; | ||
|
||
public function __construct() { | ||
Environment::setup(); | ||
error_reporting(~E_DEPRECATED); | ||
$loader = new ContainerLoader(__TEMP__DIR__, true); | ||
|
||
$class = $loader->load(function (Compiler $compiler) { | ||
|
||
$compiler->addExtension('orm', new ORMExtension()); | ||
$compiler->addExtension('database', new DatabaseExtension()); | ||
$compiler->loadConfig(__DIR__ . '/../config.neon'); | ||
}); | ||
|
||
$this->container = new $class(); | ||
} | ||
|
||
public function setUp() { | ||
Environment::lock('DB', __TEMP__DIR__); | ||
/** @var Explorer $explorer */ | ||
$explorer = $this->container->getByType(Explorer::class); | ||
$explorer->query("DELETE FROM `participant`; | ||
DELETE FROM `event`; | ||
INSERT INTO `event` (event_id, begin, end) | ||
VALUES (1, '2010-01-01', '2010-02-01'), | ||
(2, '2010-02-01', '2010-03-01'), | ||
(3, '2010-03-01', '2010-04-01'); | ||
INSERT INTO `participant` (participant_id,event_id, name) | ||
VALUES (1,1, 'Adam'), | ||
(2,1, 'Bára'), | ||
(3,1, 'Cecilia'), | ||
(4,2, 'Dano'), | ||
(5,2, 'Emil'), | ||
(6,3, 'Fero'), | ||
(7,3, 'Gustav'), | ||
(8,3, 'Husák');"); | ||
parent::setUp(); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
namespace Fykosak\NetteORM\Tests\Tests; | ||
|
||
use Fykosak\NetteORM\AbstractService; | ||
use Fykosak\NetteORM\Tests\ORM\ServiceEvent; | ||
use Fykosak\NetteORM\Tests\ORM\ServiceParticipant; | ||
use Tester\Assert; | ||
|
||
require_once __DIR__ . '/AbstractTestCase.php'; | ||
|
||
class ClassLoadTest extends AbstractTestCase { | ||
|
||
public function testAlias(): void { | ||
$serviceEvent = $this->container->getByName('orm.event.service'); | ||
Assert::type(AbstractService::class, $serviceEvent); | ||
Assert::type(ServiceEvent::class, $serviceEvent); | ||
|
||
$serviceEvent = $this->container->getByName('orm.participant.service'); | ||
Assert::type(AbstractService::class, $serviceEvent); | ||
Assert::type(ServiceParticipant::class, $serviceEvent); | ||
} | ||
} | ||
|
||
$testCase = new ClassLoadTest(); | ||
$testCase->run(); |
Oops, something went wrong.