Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge branch 'hotfix/27'
Browse files Browse the repository at this point in the history
Close #27
  • Loading branch information
weierophinney committed Oct 11, 2016
2 parents f9d3390 + 5fcc013 commit 228f2ba
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 3 deletions.
7 changes: 5 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

All notable changes to this project will be documented in this file, in reverse chronological order by release.

## 1.2.1 - TBD
## 1.2.1 - 2016-10-11

### Added

Expand All @@ -18,7 +18,10 @@ All notable changes to this project will be documented in this file, in reverse

### Fixed

- Nothing.
- [#27](https://github.com/zfcampus/zf-apigility-documentation-swagger/pull/27)
fixes the `SwaggerUiControllerFactory` to properly use the `$container`
variable, not the nonexistent `$services` variable, when pulling the
`ApiFactory` to inject in the controller.

## 1.2.0 - 2016-07-14

Expand Down
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
72 changes: 72 additions & 0 deletions test/SwaggerUiControllerFactoryTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?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\Exception\ServiceNotCreatedException;
use Zend\ServiceManager\ServiceManager;
use Zend\Test\PHPUnit\Controller\AbstractHttpControllerTestCase;
use ZF\Apigility\Documentation\ApiFactory;
use ZF\Apigility\Documentation\Swagger\SwaggerUiController;
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();
}

public function testExceptionThrownOnMissingApiCreatorClass()
{
$smFactory = $this->factory;
$this->setExpectedException(ServiceNotCreatedException::class);
$factory = $smFactory($this->services, SwaggerUiController::class);
}

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(SwaggerUiControllerFactory::class, $smFactory);

$controller = $smFactory($this->services, SwaggerUiController::class);
$this->assertInstanceOf(SwaggerUiController::class, $controller);
}
}

0 comments on commit 228f2ba

Please sign in to comment.