Skip to content

Commit

Permalink
Added unit tests for dependency injection
Browse files Browse the repository at this point in the history
  • Loading branch information
core23 committed Feb 26, 2017
1 parent 6a54402 commit dd61ea6
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
52 changes: 52 additions & 0 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php

/*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Core23\LastFmBundle\Tests\DependencyInjection;

use Core23\LastFmBundle\DependencyInjection\Configuration;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Config\Definition\Processor;

class ConfigurationTest extends TestCase
{
public function testOptions()
{
$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), array(array(
'api' => array(
'app_id' => 'foo_id',
'shared_secret' => 'bar_secret',
),
)));

$expected = array(
'api' => array(
'app_id' => 'foo_id',
'shared_secret' => 'bar_secret',
'endpoint' => 'http://ws.audioscrobbler.com/2.0/',
'auth_url' => 'http://www.last.fm/api/auth/',
),
'auth_success' => array(
'route' => null,
'route_parameters' => array(),
),
'auth_error' => array(
'route' => null,
'route_parameters' => array(),
),
'http' => array(
'client' => 'httplug.client.default',
'message_factory' => 'httplug.message_factory.default',
),
);

$this->assertSame($expected, $config);
}
}
46 changes: 46 additions & 0 deletions Tests/DependencyInjection/Core23LastFmExtensionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/*
* (c) Christian Gripp <mail@core23.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Core23\LastFmBundle\Tests\DependencyInjection;

use Core23\LastFmBundle\DependencyInjection\Core23LastFmExtension;
use Matthias\SymfonyDependencyInjectionTest\PhpUnit\AbstractExtensionTestCase;

class Core23LastFmExtensionTest extends AbstractExtensionTestCase
{
public function testLoadDefault()
{
$this->load(array(
'api' => array(
'app_id' => 'foo_id',
'shared_secret' => 'bar_secret',
),
));

$this->assertContainerBuilderHasParameter('core23.lastfm.auth_success.redirect_route', null);
$this->assertContainerBuilderHasParameter('core23.lastfm.auth_success.redirect_route_params', array());
$this->assertContainerBuilderHasParameter('core23.lastfm.auth_error.redirect_route', null);
$this->assertContainerBuilderHasParameter('core23.lastfm.auth_error.redirect_route_params', array());

$this->assertContainerBuilderHasParameter('core23.lastfm.api.app_id', 'foo_id');
$this->assertContainerBuilderHasParameter('core23.lastfm.api.shared_secret', 'bar_secret');
$this->assertContainerBuilderHasParameter('core23.lastfm.api.endpoint', 'http://ws.audioscrobbler.com/2.0/');
$this->assertContainerBuilderHasParameter('core23.lastfm.api.auth_url', 'http://www.last.fm/api/auth/');

$this->assertContainerBuilderHasAlias('core23.lastfm.http.client', 'httplug.client.default');
$this->assertContainerBuilderHasAlias('core23.lastfm.http.message_factory', 'httplug.message_factory.default');
}

protected function getContainerExtensions()
{
return array(
new Core23LastFmExtension(),
);
}
}
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.0",
"matthiasnoback/symfony-dependency-injection-test": "^1.1",
"php-http/mock-client": "^0.3",
"phpunit/phpunit": "^5.7",
"sllh/php-cs-fixer-styleci-bridge": "^2.0",
Expand Down

0 comments on commit dd61ea6

Please sign in to comment.