NelmioApiDocBundle/Tests/Command/DumpCommandTest.php

109 lines
3.4 KiB
PHP
Raw Normal View History

<?php
2015-11-10 01:27:09 +01:00
/*
* This file is part of the NelmioApiDocBundle.
*
* (c) Nelmio <hello@nelm.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace NelmioApiDocBundle\Tests\Command;
use Nelmio\ApiDocBundle\Tests\WebTestCase;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Tester\ApplicationTester;
use Symfony\Component\PropertyAccess\PropertyAccess;
class DumpCommandTest extends WebTestCase
{
/**
* @dataProvider viewProvider
*
2015-10-22 14:42:59 +02:00
* @param string $view Command view option value
* @param array $expectedMethodsCount Expected resource methods count
* @param array $expectedMethodValues Expected resource method values
*/
2024-10-01 15:54:04 +03:00
public function testDumpWithViewOption($view, array $expectedMethodsCount, array $expectedMethodValues): void
{
$this->getContainer();
$application = new Application(static::$kernel);
$application->setCatchExceptions(false);
$application->setAutoExit(false);
$tester = new ApplicationTester($application);
2024-10-01 15:54:04 +03:00
$input = [
'command' => 'api:doc:dump',
'--view' => $view,
'--format' => 'json',
2024-10-01 15:54:04 +03:00
];
$tester->run($input);
$display = $tester->getDisplay();
$this->assertJson($display);
$json = json_decode($display);
$accessor = PropertyAccess::createPropertyAccessor();
foreach ($expectedMethodsCount as $propertyPath => $expectedCount) {
$this->assertCount($expectedCount, $accessor->getValue($json, $propertyPath));
}
foreach ($expectedMethodValues as $propertyPath => $expectedValue) {
$this->assertEquals($expectedValue, $accessor->getValue($json, $propertyPath));
}
}
/**
* @return array
*/
public static function viewProvider()
{
2024-10-01 15:54:04 +03:00
return [
'test' => [
'test',
2024-10-01 15:54:04 +03:00
[
'/api/resources' => 1,
2024-10-01 15:54:04 +03:00
],
[
'/api/resources[0].method' => 'GET',
'/api/resources[0].uri' => '/api/resources.{_format}',
2024-10-01 15:54:04 +03:00
],
],
'premium' => [
'premium',
2024-10-01 15:54:04 +03:00
[
'/api/resources' => 2,
2024-10-01 15:54:04 +03:00
],
[
'/api/resources[0].method' => 'GET',
'/api/resources[0].uri' => '/api/resources.{_format}',
'/api/resources[1].method' => 'POST',
'/api/resources[1].uri' => '/api/resources.{_format}',
2024-10-01 15:54:04 +03:00
],
],
'default' => [
'default',
2024-10-01 15:54:04 +03:00
[
'/api/resources' => 4,
2024-10-01 15:54:04 +03:00
],
[
'/api/resources[0].method' => 'GET',
'/api/resources[0].uri' => '/api/resources.{_format}',
'/api/resources[1].method' => 'POST',
'/api/resources[1].uri' => '/api/resources.{_format}',
2015-04-30 15:34:19 +02:00
'/api/resources[2].method' => 'DELETE',
'/api/resources[2].uri' => '/api/resources/{id}.{_format}',
2015-04-30 15:34:19 +02:00
'/api/resources[3].method' => 'GET',
'/api/resources[3].uri' => '/api/resources/{id}.{_format}',
2024-10-01 15:54:04 +03:00
],
],
];
}
}