-
-
Notifications
You must be signed in to change notification settings - Fork 840
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: cleanup Areas annotation (#2431)
## Description Cleans up the `Area` annotation/attribute to trigger a deprecation warning whenever a list of strings isn't passed. ## What type of PR is this? (check all applicable) - [ ] Bug Fix - [ ] Feature - [ ] Refactor - [x] Deprecation - [ ] Breaking Change - [ ] Documentation Update - [ ] CI ## Checklist - [ ] I have made corresponding changes to the documentation (`docs/`) - [x] I have made corresponding changes to the changelog (`CHANGELOG.md`)
- Loading branch information
1 parent
3aaa734
commit cdc855e
Showing
5 changed files
with
131 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the NelmioApiDocBundle package. | ||
* | ||
* (c) Nelmio | ||
* | ||
* For the full copyright and license information, please view the LICENSE | ||
* file that was distributed with this source code. | ||
*/ | ||
|
||
namespace Nelmio\ApiDocBundle\Tests\Attribute; | ||
|
||
use Nelmio\ApiDocBundle\Attribute\Areas; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class AreasTest extends TestCase | ||
{ | ||
/** | ||
* @dataProvider provideData | ||
* | ||
* @param string[] $areas | ||
*/ | ||
public function testConstruct(array $areas): void | ||
{ | ||
$areasAttribute = new Areas($areas); | ||
|
||
foreach ($areas as $area) { | ||
self::assertTrue($areasAttribute->has($area)); | ||
} | ||
} | ||
|
||
/** | ||
* @dataProvider provideData | ||
* | ||
* @param string[] $areas | ||
* | ||
* @group legacy | ||
*/ | ||
public function testDeprecatedConstruct(array $areas): void | ||
{ | ||
$areasAttribute = new Areas(['value' => $areas]); | ||
|
||
foreach ($areas as $area) { | ||
self::assertTrue($areasAttribute->has($area)); | ||
} | ||
} | ||
|
||
public static function provideData(): \Generator | ||
{ | ||
yield [ | ||
['foo', 'bar'], | ||
]; | ||
|
||
yield [ | ||
['foo'] | ||
]; | ||
|
||
yield [ | ||
['bar'] | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider provideInvalidData | ||
* | ||
* @param string[] $areas | ||
*/ | ||
public function testItChecksArrayItemType(array $areas): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
self::expectExceptionMessage('An area must be given as a string'); | ||
|
||
new Areas($areas); | ||
} | ||
|
||
public function testItChecksEmptyArray(): void | ||
{ | ||
self::expectException(\InvalidArgumentException::class); | ||
self::expectExceptionMessage('A list of areas was expected'); | ||
|
||
new Areas([]); | ||
} | ||
|
||
public static function provideInvalidData(): \Generator | ||
{ | ||
yield [ | ||
['foo', 'bar', 42], | ||
]; | ||
|
||
yield [ | ||
['foo', 'bar', []], | ||
]; | ||
|
||
yield [ | ||
['foo', 'bar', new \stdClass()], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters