Skip to content

Commit 239ed1a

Browse files
Neutron-ProNeutron-Pro
authored andcommitted
Add PHPUnit tests
1 parent 857d08e commit 239ed1a

File tree

7 files changed

+137
-2
lines changed

7 files changed

+137
-2
lines changed

.github/workflows/tests.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Tests
2+
on:
3+
pull_request: null
4+
push:
5+
branches:
6+
- develop
7+
jobs:
8+
tests:
9+
runs-on: 'Ubuntu-20.04'
10+
strategy:
11+
fail-fast: false
12+
matrix:
13+
php: ['7.1', '7.2', '7.3', '7.4', '8.0']
14+
include:
15+
- php: '7.1'
16+
dependencies: 'lowest'
17+
composer-options: '--prefer-stable'
18+
19+
name: PHP ${{ matrix.php }}
20+
steps:
21+
- uses: actions/checkout@v2
22+
- uses: shivammathur/setup-php@v2
23+
with:
24+
php-version: '${{ matrix.php }}'
25+
coverage: none
26+
ini-values: 'memory_limit=-1'
27+
- uses: "ramsey/composer-install@v1"
28+
with:
29+
dependency-versions: '${{ matrix.dependencies }}'
30+
composer-options: '${{ matrix.composer-options }}'
31+
- name: Run Unit tests
32+
run: vendor/bin/phpunit

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
.idea/
22
vendor/
3-
composer.lock
3+
composer.lock
4+
.phpunit.result.cache

composer.json

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,23 @@
1212
"autoload": {
1313
"psr-4": {
1414
"NeutronStars\\Doctrine\\Enum\\Type\\": "src/"
15-
}
15+
},
16+
"exclude-from-classmap": [
17+
"/tests/"
18+
]
1619
},
1720
"minimum-stability": "stable",
1821
"require": {
1922
"php": "^7.1 | ^8.0",
2023
"doctrine/dbal": "^2.1",
2124
"neutronstars/enum": "^1.4"
25+
},
26+
"require-dev": {
27+
"phpunit/phpunit": "^6.0 | ^7.0 | ^8.0 | ^9.0"
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"NeutronStars\\Doctrine\\Enum\\Type\\Tests\\": "tests/"
32+
}
2233
}
2334
}

phpunit.xml.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<phpunit bootstrap="./vendor/autoload.php" colors="true">
4+
<testsuites>
5+
<testsuite name="DoctrineEnumForPHPType">
6+
<directory suffix="TestDoctrineEnumType.php">./tests</directory>
7+
</testsuite>
8+
</testsuites>
9+
</phpunit>

tests/Fixture/FooBarEnum.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeutronStars\Doctrine\Enum\Type\Tests\Fixture;
6+
7+
use NeutronStars\Enum\Enum;
8+
9+
/**
10+
* @method static self FOO()
11+
* @method static self BAR()
12+
* Class FooBarEnum
13+
* @package NeutronStars\Doctrine\Enum\Type\Tests\Fixture
14+
*/
15+
class FooBarEnum extends Enum
16+
{
17+
public const FOO = 'Foo';
18+
public const BAR = 'Bar';
19+
}

tests/Fixture/FooBarEnumType.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeutronStars\Doctrine\Enum\Type\Tests\Fixture;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use NeutronStars\Doctrine\Enum\Type\EnumType;
9+
10+
class FooBarEnumType extends EnumType
11+
{
12+
/**
13+
* @return string
14+
*/
15+
public function getName()
16+
{
17+
return 'foo_bar_enum_type';
18+
}
19+
20+
/**
21+
* @param mixed $value
22+
* @param AbstractPlatform $platform
23+
* @return string|void|null
24+
* @throws \ReflectionException
25+
*/
26+
public function convertToPHPValue($value, $platform)
27+
{
28+
return FooBarEnum::from($value);
29+
}
30+
}

tests/TestDoctrineEnumType.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace NeutronStars\Doctrine\Enum\Type\Tests;
6+
7+
use Doctrine\DBAL\Platforms\AbstractPlatform;
8+
use Doctrine\DBAL\Platforms\PostgreSQL100Platform;
9+
use Doctrine\DBAL\Types\Type;
10+
use NeutronStars\Doctrine\Enum\Type\Tests\Fixture\FooBarEnum;
11+
use NeutronStars\Doctrine\Enum\Type\Tests\Fixture\FooBarEnumType;
12+
use PHPUnit\Framework\TestCase;
13+
14+
class TestDoctrineEnumType extends TestCase
15+
{
16+
public function testConvertToDataBaseValue()
17+
{
18+
$enumType = new FooBarEnumType();
19+
$this->assertSame(
20+
'BAR',
21+
$enumType->convertToDatabaseValue(FooBarEnum::BAR(), new PostgreSQL100Platform())
22+
);
23+
}
24+
25+
public function testConvertToPHPValue()
26+
{
27+
$enumType = new FooBarEnumType();
28+
$this->assertSame(
29+
FooBarEnum::FOO(),
30+
$enumType->convertToPHPValue('FOO', new PostgreSQL100Platform())
31+
);
32+
}
33+
}

0 commit comments

Comments
 (0)