/
githubmirror
/
symfony
Обзор
Документация
Войти
/
githubmirror
/
symfony
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
8.2
src/Symfony/Component/WebLink/Tests/LinkTest.php
106 строк
3 KB
Christian Flothmann
replace PHPUnit annotations with attributes
04 авг 2025, 10:05
04 авг 2025, 10:05
982f89c
Код
Авторство
О чём код?
<?php /* * This file is part of the Symfony package. * * (c) Fabien Potencier <fabien@symfony.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace Symfony\Component\WebLink\Tests; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\WebLink\Link; /** * Test case borrowed from https://github.com/php-fig/link/. */ class LinkTest extends TestCase { public function testCanSetAndRetrieveValues() { $link = (new Link()) ->withHref('http://www.google.com') ->withRel('next') ->withAttribute('me', 'you') ; $this->assertSame('http://www.google.com', $link->getHref()); $this->assertContains('next', $link->getRels()); $this->assertArrayHasKey('me', $link->getAttributes()); $this->assertSame('you', $link->getAttributes()['me']); } public function testCanRemoveValues() { $link = (new Link()) ->withHref('http://www.google.com') ->withRel('next') ->withAttribute('me', 'you') ; $link = $link->withoutAttribute('me') ->withoutRel('next'); $this->assertSame('http://www.google.com', $link->getHref()); $this->assertFalse(\in_array('next', $link->getRels(), true)); $this->assertArrayNotHasKey('me', $link->getAttributes()); } public function testMultipleRels() { $link = (new Link()) ->withHref('http://www.google.com') ->withRel('next') ->withRel('reference'); $this->assertCount(2, $link->getRels()); $this->assertContains('next', $link->getRels()); $this->assertContains('reference', $link->getRels()); } public function testConstructor() { $link = new Link('next', 'http://www.google.com'); $this->assertSame('http://www.google.com', $link->getHref()); $this->assertContains('next', $link->getRels()); } #[DataProvider('templatedHrefProvider')] public function testTemplated(string $href) { $link = (new Link()) ->withHref($href); $this->assertTrue($link->isTemplated()); } #[DataProvider('notTemplatedHrefProvider')] public function testNotTemplated(string $href) { $link = (new Link()) ->withHref($href); $this->assertFalse($link->isTemplated()); } public static function templatedHrefProvider() { return [ ['http://www.google.com/{param}/foo'], ['http://www.google.com/foo?q={param}'], ]; } public static function notTemplatedHrefProvider() { return [ ['http://www.google.com/foo'], ['/foo/bar/baz'], ]; } }