These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Kunstmaan\SitemapBundle\Tests\unit\Model; |
||
4 | |||
5 | use Kunstmaan\SitemapBundle\Model\SitemapUrl; |
||
6 | use PHPUnit\Framework\TestCase; |
||
7 | |||
8 | class SitemapUrlTest extends TestCase |
||
9 | { |
||
10 | /** |
||
11 | * @dataProvider priorityDataProvider |
||
12 | */ |
||
13 | public function testPriorityValues(float $priority, bool $expectException) |
||
14 | { |
||
15 | if ($expectException) { |
||
16 | $this->expectException(\InvalidArgumentException::class); |
||
17 | $this->expectExceptionMessage(sprintf('A sitemap url priority can\'t be higher than 1 or below 0. Value given "%s"', $priority)); |
||
18 | } |
||
19 | |||
20 | $obj = new SitemapUrl('example-url', new \DateTimeImmutable(), $priority); |
||
21 | |||
22 | if (!$expectException) { |
||
23 | $this->assertInstanceOf(SitemapUrl::class, $obj); |
||
24 | $this->assertSame($priority, $obj->getPriority()); |
||
25 | } |
||
26 | } |
||
27 | |||
28 | View Code Duplication | public function priorityDataProvider() |
|
0 ignored issues
–
show
|
|||
29 | { |
||
30 | return [ |
||
31 | [0.0, false], |
||
32 | [-1.0, true], |
||
33 | [1.0, false], |
||
34 | [1.2, true], |
||
35 | ]; |
||
36 | } |
||
37 | } |
||
38 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.