-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTechTest.php
More file actions
68 lines (61 loc) · 2.07 KB
/
TechTest.php
File metadata and controls
68 lines (61 loc) · 2.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
namespace App\Tests\Entity;
use App\Entity\Category;
use App\Entity\Request;
use App\Entity\Tech;
use App\Enum\TechTypeEnum;
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
use Symfony\Component\Validator\ConstraintViolation;
use Symfony\Component\Validator\Validator\ValidatorInterface;
final class TechTest extends KernelTestCase
{
private ValidatorInterface $validator;
protected function setUp(): void
{
self::bootKernel();
$this->validator = self::getContainer()->get(ValidatorInterface::class);
}
public static function techProvider(): array
{
return [
'Valid' => [0, (new Tech())
->setName('Tech')
->setDescription('Tech desc')
->addCategory(new Category())
->setRequest(new Request()),
],
'Invalid dependsOn (null but is required for type Library)' => [1, (new Tech())
->setName('Tech')
->setDescription('Tech desc')
->setType(TechTypeEnum::Library)
->addCategory(new Category())
->setRequest(new Request()),
],
'Invalid GitHub URL' => [1, (new Tech())
->setName('Tech')
->setDescription('Tech desc')
->setLinks([Tech::LINK_GITHUB => 'https://not-github.com'])
->addCategory(new Category())
->setRequest(new Request()),
],
];
}
/**
* @dataProvider techProvider
*/
public function testTechs(int $numErrors, Tech $tech): void
{
$errors = $this->validator->validate($tech);
$count = \count($errors);
$this->assertEquals(
$numErrors,
$count,
sprintf(
'Expected %s error(s) but got %s error(s) instead. Errors : %s',
$numErrors,
$count,
\PHP_EOL.implode(\PHP_EOL, array_map(static fn (ConstraintViolation $error): string => $error->getMessage(), [...$errors]))
)
);
}
}