Skip to content
This repository was archived by the owner on Jan 21, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SwaggerUiControllerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
));
}

return new SwaggerUiController($services->get(ApiFactory::class));
return new SwaggerUiController($container->get(ApiFactory::class));
}

/**
Expand Down
78 changes: 78 additions & 0 deletions test/SwaggerUiControllerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* @license http://opensource.org/licenses/BSD-3-Clause BSD-3-Clause
* @copyright Copyright (c) 2014-2016 Zend Technologies USA Inc. (http://www.zend.com)
*/

namespace ZFTest\Apigility\Documentation\Swagger;

use PHPUnit_Framework_TestCase as TestCase;
use Zend\ModuleManager\ModuleManager;
use Zend\ServiceManager\ServiceManager;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
use ZF\Apigility\Documentation\ApiFactory;
use ZF\Apigility\Documentation\Swagger\SwaggerUiControllerFactory;
use ZF\Apigility\Provider\ApigilityProviderInterface;
use ZF\Configuration\ModuleUtils;

class SwaggerUiControllerFactoryTest extends TestCase
{
/**
* @var SwaggerUiControllerFactory
*/
protected $factory;

/**
* @var ServiceManager
*/
protected $services;


protected function setUp()
{
$this->factory = new SwaggerUiControllerFactory();
$this->services = $services = new ServiceManager();

parent::setUp();
}

/**
* @expectedException \Zend\ServiceManager\Exception\ServiceNotCreatedException
*/
public function testExceptionThrownOnMissingApiCreatorClass()
{
$smFactory = $this->factory;
$factory = $smFactory($this->services, 'SwaggerUiControllerFactory');
$this->assertInstanceOf('ZF\Apigility\Documentation\Swagger\SwaggerUiControllerFactory', $factory);

$factory();
}

public function testCreatesServiceWithDefaults()
{
$mockModule = $this->prophesize(ApigilityProviderInterface::class)->reveal();

$moduleManager = $this->prophesize(ModuleManager::class);
$moduleManager->getModules()->willReturn(['Test']);
$moduleManager->getModule('Test')->willReturn($mockModule);
$moduleUtils = $this->prophesize(ModuleUtils::class);
$moduleUtils
->getModuleConfigPath('Test')
->willReturn([]);

$apiFactory = new ApiFactory(
$moduleManager->reveal(),
[],
$moduleUtils->reveal()
);

$this->services->setService(ApiFactory::class, $apiFactory);

/** @var SwaggerUiControllerFactory $service */
$smFactory = $this->factory;
$this->assertInstanceOf('ZF\Apigility\Documentation\Swagger\SwaggerUiControllerFactory', $smFactory);

$controller = $smFactory($this->services, 'SwaggerUiControllerFactory');
$this->assertInstanceOf('ZF\Apigility\Documentation\Swagger\SwaggerUiController', $controller);
}
}