Skip to content

Commit 0777e9d

Browse files
Neutron-ProNeutron-Pro
authored andcommitted
Ajout des test unitaires
1 parent c3bbb1f commit 0777e9d

File tree

6 files changed

+106
-1
lines changed

6 files changed

+106
-1
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
composer.lock
3-
vendor/
3+
vendor/
4+
.phpunit.result.cache

composer.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,17 @@
1818
"autoload": {
1919
"psr-4": {
2020
"NeutronStars\\Symfony\\Enum\\Normalizer\\": "src/"
21+
},
22+
"exclude-from-classmap": [
23+
"/tests/"
24+
]
25+
},
26+
"require-dev": {
27+
"phpunit/phpunit": "^6.0 | ^7.0 | ^8.0 | ^9.0"
28+
},
29+
"autoload-dev": {
30+
"psr-4": {
31+
"NeutronStars\\Symfony\\Enum\\Normalizer\\Tests\\": "tests/"
2132
}
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="SymfonyNormalizerEnumForPHP">
6+
<directory suffix="TestNormalizerEnum.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\Symfony\Enum\Normalizer\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\Symfony\Enum\Normalizer\Tests\Fixture
14+
*/
15+
class FooBarEnum extends Enum
16+
{
17+
public const FOO = 'Foo';
18+
public const BAR = 'Bar';
19+
}

tests/TestNormalizerEnum.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\Symfony\Enum\Normalizer\Tests;
6+
7+
use NeutronStars\Symfony\Enum\Normalizer\EnumDenormalizer;
8+
use NeutronStars\Symfony\Enum\Normalizer\EnumNormalizer;
9+
use NeutronStars\Symfony\Enum\Normalizer\Tests\Fixture\FooBarEnum;
10+
use PHPUnit\Framework\TestCase;
11+
12+
class TestNormalizerEnum extends TestCase
13+
{
14+
public function testNormalizeEnum(): void
15+
{
16+
$normalizer = new EnumNormalizer(FooBarEnum::class);
17+
$this->assertSame(
18+
'BAR',
19+
$normalizer->normalize(FooBarEnum::BAR()),
20+
'Unable to normalize the FooBarEnum.'
21+
);
22+
}
23+
24+
public function testDenormalizeEnum(): void
25+
{
26+
$denormalizer = new EnumDenormalizer(FooBarEnum::class);
27+
$this->assertSame(
28+
FooBarEnum::FOO(),
29+
$denormalizer->denormalize('FOO', FooBarEnum::class),
30+
'Unable to denormalize the FooBarEnum.'
31+
);
32+
}
33+
}

0 commit comments

Comments
 (0)