Vendor update && Started using DoctrineMigrations
This commit is contained in:
@@ -0,0 +1,127 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\Reference;
|
||||
|
||||
use Symfony\Component\DependencyInjection\DefinitionDecorator;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use JMS\DiExtraBundle\DependencyInjection\JMSDiExtraExtension;
|
||||
use Symfony\Component\HttpKernel\KernelInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use JMS\DiExtraBundle\DependencyInjection\Compiler\AnnotationConfigurationPass;
|
||||
|
||||
class AnnotationConfigurationPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = $this->getContainer(array(), array(
|
||||
__DIR__.'/../../Fixture/',
|
||||
));
|
||||
$container->set('doctrine.entity_manager', $em = new \stdClass);
|
||||
$container->set('session', $session = new \stdClass);
|
||||
$container->set('database_connection', $dbCon = new \stdClass);
|
||||
$container->set('router', $router = new \stdClass);
|
||||
$container->setParameter('table_name', 'foo');
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('j_m_s.di_extra_bundle.tests.fixture.request_listener'));
|
||||
$service = $container->get('j_m_s.di_extra_bundle.tests.fixture.request_listener');
|
||||
$this->assertAttributeEquals($em, 'em', $service);
|
||||
$this->assertAttributeEquals($session, 'session', $service);
|
||||
$this->assertAttributeEquals($dbCon, 'con', $service);
|
||||
$this->assertAttributeEquals($router, 'router', $service);
|
||||
$this->assertAttributeEquals('foo', 'table', $service);
|
||||
}
|
||||
|
||||
public function testProcessValidator()
|
||||
{
|
||||
$container = $this->getContainer(array(), array(
|
||||
__DIR__.'/../../Fixture/Validator',
|
||||
));
|
||||
$container->set('foo', $foo = new \stdClass);
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('j_m_s.di_extra_bundle.tests.fixture.validator.validator'));
|
||||
|
||||
$def = $container->getDefinition('j_m_s.di_extra_bundle.tests.fixture.validator.validator');
|
||||
$this->assertEquals(array(
|
||||
'validator.constraint_validator' => array(
|
||||
array('alias' => 'foobar'),
|
||||
)
|
||||
), $def->getTags());
|
||||
|
||||
$v = $container->get('j_m_s.di_extra_bundle.tests.fixture.validator.validator');
|
||||
$this->assertAttributeEquals($foo, 'foo', $v);
|
||||
}
|
||||
|
||||
public function testConstructorWithInheritance()
|
||||
{
|
||||
$container = $this->getContainer(array(), array(
|
||||
__DIR__.'/../../Functional/Bundle/TestBundle/Inheritance',
|
||||
));
|
||||
$container->set('foo', $foo = new \stdClass);
|
||||
$container->set('bar', $bar = new \stdClass);
|
||||
$this->process($container);
|
||||
|
||||
$this->assertTrue($container->hasDefinition('concrete_class'));
|
||||
$this->assertTrue($container->hasDefinition('abstract_class'));
|
||||
|
||||
$def = new DefinitionDecorator('abstract_class');
|
||||
$def->setClass('JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Inheritance\ConcreteClass');
|
||||
$def->addArgument(new Reference('foo'));
|
||||
$def->addArgument(new Reference('bar'));
|
||||
|
||||
$this->assertEquals($def, $container->getDefinition('concrete_class'));
|
||||
}
|
||||
|
||||
private function getContainer(array $bundles = array(), array $directories = array())
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->set('annotation_reader', new AnnotationReader());
|
||||
$container->setParameter('kernel.debug', false);
|
||||
|
||||
$extension = new JMSDiExtraExtension();
|
||||
$extension->load(array(array(
|
||||
'locations' => array(
|
||||
'bundles' => $bundles,
|
||||
'directories' => $directories,
|
||||
),
|
||||
'metadata' => array(
|
||||
'cache' => 'none',
|
||||
)
|
||||
)), $container);
|
||||
|
||||
return $container;
|
||||
}
|
||||
|
||||
private function process(ContainerBuilder $container, array $bundles = array())
|
||||
{
|
||||
$kernel = $this->getMock('Symfony\Component\HttpKernel\KernelInterface');
|
||||
$kernel
|
||||
->expects($this->once())
|
||||
->method('getBundles')
|
||||
->will($this->returnValue($bundles))
|
||||
;
|
||||
|
||||
$pass = new AnnotationConfigurationPass($kernel);
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\DependencyInjection\Compiler;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use JMS\DiExtraBundle\DependencyInjection\Compiler\ResourceOptimizationPass;
|
||||
use Symfony\Component\Config\Resource\DirectoryResource;
|
||||
|
||||
class ResourceOptimizationPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testProcess()
|
||||
{
|
||||
$container = new ContainerBuilder();
|
||||
$container->addResource(new DirectoryResource(__DIR__.'/Fixtures/a'));
|
||||
$container->addResource(new DirectoryResource(__DIR__.'/Fixtures/a/b'));
|
||||
$container->addResource(new DirectoryResource(__DIR__.'/Fixtures/c'));
|
||||
$this->process($container);
|
||||
|
||||
$resources = $container->getResources();
|
||||
$this->assertEquals(1, count($resources));
|
||||
$this->assertInstanceOf('JMS\DiExtraBundle\Config\FastDirectoriesResource', $resources[0]);
|
||||
$this->assertEquals(array(
|
||||
__DIR__.'/Fixtures/a',
|
||||
__DIR__.'/Fixtures/c'
|
||||
), $resources[0]->getResource());
|
||||
$this->assertAttributeEquals('*', 'filePattern', $resources[0]);
|
||||
}
|
||||
|
||||
private function process(ContainerBuilder $container)
|
||||
{
|
||||
$pass = new ResourceOptimizationPass();
|
||||
$pass->process($container);
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Finder;
|
||||
|
||||
use JMS\DiExtraBundle\Finder\PatternFinder;
|
||||
use Symfony\Component\Process\ExecutableFinder;
|
||||
|
||||
abstract class AbstractPatternFinderTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFindFiles()
|
||||
{
|
||||
$finder = $this->getFinder();
|
||||
|
||||
$expectedFiles = array(
|
||||
realpath(__DIR__.'/../Fixture/NonEmptyDirectory/Service1.php'),
|
||||
realpath(__DIR__.'/../Fixture/NonEmptyDirectory/SubDir1/Service2.php'),
|
||||
realpath(__DIR__.'/../Fixture/NonEmptyDirectory/SubDir2/Service3.php'),
|
||||
);
|
||||
|
||||
$foundFiles = $finder->findFiles(array(__DIR__.'/../Fixture/NonEmptyDirectory'));
|
||||
$foundFiles = array_map('realpath', $foundFiles);
|
||||
|
||||
$this->assertEquals(array(), array_diff($expectedFiles, $foundFiles));
|
||||
$this->assertEquals(array(), array_diff($foundFiles, $expectedFiles));
|
||||
}
|
||||
|
||||
public function testFindFilesUsingGrepReturnsEmptyArrayWhenNoMatchesAreFound()
|
||||
{
|
||||
$finder = $this->getFinder();
|
||||
$this->assertEquals(array(), $finder->findFiles(array(__DIR__.'/../Fixture/EmptyDirectory')));
|
||||
}
|
||||
|
||||
abstract protected function getFinder();
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Finder;
|
||||
|
||||
use JMS\DiExtraBundle\Finder\PatternFinder;
|
||||
|
||||
class FindstrPatternFinderTest extends AbstractPatternFinderTest
|
||||
{
|
||||
protected function getFinder()
|
||||
{
|
||||
if (0 !== stripos(PHP_OS, 'win')) {
|
||||
$this->markTestSkipped('FINDSTR is only available on Windows.');
|
||||
}
|
||||
|
||||
$finder = new PatternFinder('JMS\DiExtraBundle\Annotation');
|
||||
$ref = new \ReflectionProperty($finder, 'method');
|
||||
$ref->setAccessible(true);
|
||||
$ref->setValue($finder, PatternFinder::METHOD_FINDSTR);
|
||||
|
||||
return $finder;
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Finder;
|
||||
|
||||
use JMS\DiExtraBundle\Finder\PatternFinder;
|
||||
|
||||
class GrepPatternFinderTest extends AbstractPatternFinderTest
|
||||
{
|
||||
protected function getFinder()
|
||||
{
|
||||
$finder = new PatternFinder('JMS\DiExtraBundle\Annotation');
|
||||
|
||||
$ref = new \ReflectionProperty($finder, 'grepPath');
|
||||
$ref->setAccessible(true);
|
||||
if (null === $v = $ref->getValue($finder)) {
|
||||
$this->markTestSkipped('grep is not available on your system.');
|
||||
}
|
||||
|
||||
return $finder;
|
||||
}
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Finder;
|
||||
|
||||
use JMS\DiExtraBundle\Finder\PatternFinder;
|
||||
|
||||
class PhpPatternFinderTest extends AbstractPatternFinderTest
|
||||
{
|
||||
protected function getFinder()
|
||||
{
|
||||
$finder = new PatternFinder('JMS\DiExtraBundle\Annotation');
|
||||
$ref = new \ReflectionProperty($finder, 'method');
|
||||
$ref->setAccessible(true);
|
||||
$ref->setValue($finder, PatternFinder::METHOD_FINDER);
|
||||
|
||||
return $finder;
|
||||
}
|
||||
}
|
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Fixture;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\Inject;
|
||||
|
||||
/**
|
||||
* Login Controller.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class LoginController
|
||||
{
|
||||
/**
|
||||
* @Inject("form.csrf_provider")
|
||||
*/
|
||||
private $csrfProvider;
|
||||
|
||||
/**
|
||||
* @Inject
|
||||
*/
|
||||
private $rememberMeServices;
|
||||
|
||||
/**
|
||||
* @Inject("security.context")
|
||||
*/
|
||||
private $securityContext;
|
||||
|
||||
/**
|
||||
* @Inject("security.authentication.trust_resolver")
|
||||
*/
|
||||
private $trustResolver;
|
||||
|
||||
public function loginAction()
|
||||
{
|
||||
}
|
||||
|
||||
public function getCsrfProvider()
|
||||
{
|
||||
return $this->csrfProvider;
|
||||
}
|
||||
|
||||
public function getRememberMeServices()
|
||||
{
|
||||
return $this->rememberMeServices;
|
||||
}
|
||||
|
||||
public function getSecurityContext()
|
||||
{
|
||||
return $this->securityContext;
|
||||
}
|
||||
|
||||
public function getTrustResolver()
|
||||
{
|
||||
return $this->trustResolver;
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
// just nothing in here
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Fixture\NonEmptyDirectory;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/** @DI\Service */
|
||||
class Service1
|
||||
{
|
||||
}
|
@@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace FooBar;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\Service;
|
||||
|
||||
/** @Service */
|
||||
class Foo
|
||||
{
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Fixture\NonEmptyDirectory\SubDir1;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\Service;
|
||||
|
||||
/** @Service */
|
||||
class Service2
|
||||
{
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Fixture\NonEmptyDirectory\SubDir2;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/** @DI\Service */
|
||||
class Service1
|
||||
{
|
||||
}
|
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Fixture;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @DI\Service
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class RequestListener
|
||||
{
|
||||
private $router;
|
||||
private $session;
|
||||
private $em;
|
||||
private $con;
|
||||
private $table;
|
||||
|
||||
/**
|
||||
* @DI\InjectParams({
|
||||
* "em" = @DI\Inject("doctrine.entity_manager")
|
||||
* })
|
||||
*/
|
||||
public function __construct($router, $session, $em)
|
||||
{
|
||||
$this->router = $router;
|
||||
$this->session = $session;
|
||||
$this->em = $em;
|
||||
}
|
||||
|
||||
/**
|
||||
* @DI\InjectParams({
|
||||
* "table" = @DI\Inject("%table_name%")
|
||||
* })
|
||||
*/
|
||||
public function setConnection($databaseConnection, $table)
|
||||
{
|
||||
$this->con = $databaseConnection;
|
||||
$this->table = $table;
|
||||
}
|
||||
}
|
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Fixture\Validator;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation\InjectParams;
|
||||
use JMS\DiExtraBundle\Annotation\Validator as ValidatorAnnot;
|
||||
use Symfony\Component\Validator\Constraint;
|
||||
use Symfony\Component\Validator\ConstraintValidator;
|
||||
|
||||
/**
|
||||
* @ValidatorAnnot("foobar")
|
||||
*/
|
||||
class Validator extends ConstraintValidator
|
||||
{
|
||||
private $foo;
|
||||
|
||||
/**
|
||||
* @InjectParams
|
||||
*/
|
||||
public function __construct($foo)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
}
|
||||
|
||||
public function isValid($value, Constraint $constraint)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional;
|
||||
|
||||
require_once __DIR__.'/../bootstrap.php';
|
||||
|
||||
use Symfony\Component\HttpKernel\Util\Filesystem;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\HttpKernel\Kernel;
|
||||
|
||||
class AppKernel extends Kernel
|
||||
{
|
||||
private $config;
|
||||
|
||||
public function __construct($config)
|
||||
{
|
||||
parent::__construct('test', true);
|
||||
|
||||
$fs = new Filesystem();
|
||||
if (!$fs->isAbsolutePath($config)) {
|
||||
$config = __DIR__.'/config/'.$config;
|
||||
}
|
||||
|
||||
if (!file_exists($config)) {
|
||||
throw new \RuntimeException(sprintf('The config file "%s" does not exist.', $config));
|
||||
}
|
||||
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function registerBundles()
|
||||
{
|
||||
return array(
|
||||
new \Symfony\Bundle\FrameworkBundle\FrameworkBundle(),
|
||||
new \Symfony\Bundle\SecurityBundle\SecurityBundle(),
|
||||
new \Symfony\Bundle\TwigBundle\TwigBundle(),
|
||||
new \Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(),
|
||||
new \JMS\AopBundle\JMSAopBundle(),
|
||||
new \JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\JMSDiExtraTestBundle(),
|
||||
new \JMS\DiExtraBundle\JMSDiExtraBundle($this),
|
||||
new \JMS\SecurityExtraBundle\JMSSecurityExtraBundle(),
|
||||
);
|
||||
}
|
||||
|
||||
public function registerContainerConfiguration(LoaderInterface $loader)
|
||||
{
|
||||
$loader->load($this->config);
|
||||
}
|
||||
|
||||
public function getCacheDir()
|
||||
{
|
||||
return sys_get_temp_dir().'/JMSDiExtraBundle';
|
||||
}
|
||||
|
||||
public function serialize()
|
||||
{
|
||||
return $this->config;
|
||||
}
|
||||
|
||||
public function unserialize($config)
|
||||
{
|
||||
$this->__construct($config);
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional;
|
||||
|
||||
use Symfony\Component\HttpKernel\Util\Filesystem;
|
||||
|
||||
use Symfony\Bundle\FrameworkBundle\Test\WebTestCase;
|
||||
|
||||
class BaseTestCase extends WebTestCase
|
||||
{
|
||||
static protected function createKernel(array $options = array())
|
||||
{
|
||||
return new AppKernel(
|
||||
isset($options['config']) ? $options['config'] : 'default.yml'
|
||||
);
|
||||
}
|
||||
|
||||
protected function tearDown()
|
||||
{
|
||||
$this->cleanTmpDir();
|
||||
}
|
||||
|
||||
protected function setUp()
|
||||
{
|
||||
$this->cleanTmpDir();
|
||||
}
|
||||
|
||||
private function cleanTmpDir()
|
||||
{
|
||||
$fs = new Filesystem();
|
||||
$fs->remove(sys_get_temp_dir().'/JMSDiExtraBundle');
|
||||
}
|
||||
}
|
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use JMS\SecurityExtraBundle\Annotation\Secure;
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* Secured Controller.
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class AnotherSecuredController
|
||||
{
|
||||
/**
|
||||
* @Route("/secure-action")
|
||||
* @Secure("ROLE_FOO")
|
||||
*/
|
||||
public function secureAction()
|
||||
{
|
||||
throw new \Exception('Should never be called');
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
|
||||
/**
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
abstract class RegisterController
|
||||
{
|
||||
/**
|
||||
* @Route("/register")
|
||||
*/
|
||||
public function registerAction()
|
||||
{
|
||||
$mailer = $this->getMailer();
|
||||
|
||||
return new Response($mailer->getFromMail(), 200, array('Content-Type' => 'text/plain'));
|
||||
}
|
||||
|
||||
/** @DI\LookupMethod("test_mailer") */
|
||||
abstract protected function getMailer();
|
||||
}
|
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Controller;
|
||||
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
|
||||
use JMS\SecurityExtraBundle\Annotation\Secure;
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
abstract class SecuredController
|
||||
{
|
||||
/**
|
||||
* @Route("/lookup-method-and-aop")
|
||||
* @Secure("ROLE_FOO")
|
||||
*/
|
||||
public function secureAction()
|
||||
{
|
||||
throw new \Exception('Should never be called');
|
||||
}
|
||||
|
||||
/** @DI\LookupMethod */
|
||||
abstract protected function getTestMailer();
|
||||
}
|
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Inheritance;
|
||||
|
||||
use Symfony\Component\Templating\EngineInterface;
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @DI\Service("abstract_class")
|
||||
*
|
||||
* @author johannes
|
||||
*/
|
||||
abstract class AbstractClass
|
||||
{
|
||||
private $templating;
|
||||
|
||||
/**
|
||||
* @DI\InjectParams
|
||||
*
|
||||
* @param EngineInterface $templating
|
||||
*/
|
||||
public function setTemplating(EngineInterface $templating)
|
||||
{
|
||||
$this->templating = $templating;
|
||||
}
|
||||
|
||||
public function getTemplating()
|
||||
{
|
||||
return $this->templating;
|
||||
}
|
||||
}
|
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Inheritance;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @DI\Service("concrete_class")
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class ConcreteClass extends AbstractClass
|
||||
{
|
||||
private $foo;
|
||||
private $bar;
|
||||
|
||||
/**
|
||||
* @DI\InjectParams
|
||||
*
|
||||
* @param stdClass $foo
|
||||
* @param stdClass $bar
|
||||
*/
|
||||
public function __construct($foo, $bar)
|
||||
{
|
||||
$this->foo = $foo;
|
||||
$this->bar = $bar;
|
||||
}
|
||||
|
||||
public function getFoo()
|
||||
{
|
||||
return $this->foo;
|
||||
}
|
||||
|
||||
public function getBar()
|
||||
{
|
||||
return $this->bar;
|
||||
}
|
||||
}
|
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle;
|
||||
|
||||
use Symfony\Component\HttpKernel\Bundle\Bundle;
|
||||
|
||||
class JMSDiExtraTestBundle extends Bundle
|
||||
{
|
||||
}
|
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional\Bundle\TestBundle\Mailer;
|
||||
|
||||
use JMS\DiExtraBundle\Annotation as DI;
|
||||
|
||||
/**
|
||||
* @DI\Service("test_mailer")
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class TestMailer
|
||||
{
|
||||
public function getFromMail()
|
||||
{
|
||||
return 'foo@bar.de';
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional;
|
||||
|
||||
class ControllerResolverTest extends BaseTestCase
|
||||
{
|
||||
public function testLookupMethodIsCorrectlyImplemented()
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('GET', '/register');
|
||||
|
||||
$this->assertEquals('foo@bar.de', $client->getResponse()->getContent());
|
||||
}
|
||||
|
||||
public function testLookupMethodAndAopProxy()
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('GET', '/lookup-method-and-aop');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect('http://localhost/login'), substr((string) $client->getResponse(), 0, 512));
|
||||
|
||||
$client->insulate();
|
||||
$client->request('GET', '/lookup-method-and-aop');
|
||||
$this->assertTrue($client->getResponse()->isRedirect('http://localhost/login'), substr((string) $client->getResponse(), 0, 512));
|
||||
}
|
||||
|
||||
public function testAopProxyWhenNoDiMetadata()
|
||||
{
|
||||
$client = $this->createClient();
|
||||
$client->request('GET', '/secure-action');
|
||||
|
||||
$this->assertTrue($client->getResponse()->isRedirect('http://localhost/login'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Functional;
|
||||
|
||||
class Issue11Test extends BaseTestCase
|
||||
{
|
||||
public function testConstructorInjectionWithInheritance()
|
||||
{
|
||||
$this->createClient();
|
||||
|
||||
$container = self::$kernel->getContainer();
|
||||
$foo = $container->get('foo');
|
||||
$bar = $container->get('bar');
|
||||
$templating = $container->get('templating');
|
||||
|
||||
$concreteService = $container->get('concrete_class');
|
||||
$this->assertSame($templating, $concreteService->getTemplating());
|
||||
$this->assertSame($foo, $concreteService->getFoo());
|
||||
$this->assertSame($bar, $concreteService->getBar());
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
imports:
|
||||
- { resource: framework.yml }
|
||||
- { resource: twig.yml }
|
||||
- { resource: security.yml }
|
||||
|
||||
jms_di_extra:
|
||||
locations:
|
||||
bundles: [JMSDiExtraTestBundle]
|
||||
|
||||
services:
|
||||
foo: { class: stdClass }
|
||||
bar: { class: stdClass }
|
@@ -0,0 +1,16 @@
|
||||
framework:
|
||||
secret: test
|
||||
test: ~
|
||||
session:
|
||||
storage_id: session.storage.filesystem
|
||||
form: true
|
||||
csrf_protection: true
|
||||
validation:
|
||||
enabled: true
|
||||
enable_annotations: true
|
||||
router:
|
||||
resource: %kernel.root_dir%/config/routing.yml
|
||||
|
||||
services:
|
||||
logger:
|
||||
class: Symfony\Component\HttpKernel\Log\NullLogger
|
@@ -0,0 +1,3 @@
|
||||
TestBundle:
|
||||
type: annotation
|
||||
resource: @JMSDiExtraTestBundle/Controller/
|
@@ -0,0 +1,13 @@
|
||||
security:
|
||||
providers:
|
||||
in_memory:
|
||||
users:
|
||||
johannes: { password: login }
|
||||
|
||||
encoders:
|
||||
Symfony\Component\Security\Core\User\UserInterface: plaintext
|
||||
|
||||
firewalls:
|
||||
default:
|
||||
form_login: ~
|
||||
anonymous: ~
|
@@ -0,0 +1,7 @@
|
||||
framework:
|
||||
templating:
|
||||
engines: [twig, php]
|
||||
|
||||
twig:
|
||||
debug: %kernel.debug%
|
||||
strict_variables: %kernel.debug%
|
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Metadata;
|
||||
|
||||
use JMS\DiExtraBundle\Metadata\ClassMetadata;
|
||||
|
||||
class ClassMetadataTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testSerializeUnserialize()
|
||||
{
|
||||
$classMetadata = new ClassMetadata('JMS\DiExtraBundle\Tests\Fixture\LoginController');
|
||||
$classMetadata->arguments = array('foo', 'bar');
|
||||
$classMetadata->abstract = true;
|
||||
$classMetadata->public = false;
|
||||
$classMetadata->id = 'foo';
|
||||
|
||||
$this->assertEquals($classMetadata, unserialize(serialize($classMetadata)));
|
||||
}
|
||||
}
|
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Metadata\Driver;
|
||||
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use JMS\DiExtraBundle\Metadata\Driver\AnnotationDriver;
|
||||
|
||||
class AnnotationDriverTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testFormType()
|
||||
{
|
||||
$metadata = $this->getDriver()->loadMetadataForClass(new \ReflectionClass('JMS\DiExtraBundle\Tests\Metadata\Driver\Fixture\LoginType'));
|
||||
|
||||
$this->assertEquals('j_m_s.di_extra_bundle.tests.metadata.driver.fixture.login_type', $metadata->id);
|
||||
$this->assertEquals(array(
|
||||
'form.type' => array(
|
||||
array('alias' => 'login'),
|
||||
)
|
||||
), $metadata->tags);
|
||||
}
|
||||
|
||||
public function testFormTypeWithExplicitAlias()
|
||||
{
|
||||
$metadata = $this->getDriver()->loadMetadataForClass(new \ReflectionClass('JMS\DiExtraBundle\Tests\Metadata\Driver\Fixture\SignUpType'));
|
||||
|
||||
$this->assertEquals(array(
|
||||
'form.type' => array(
|
||||
array('alias' => 'foo'),
|
||||
)
|
||||
), $metadata->tags);
|
||||
}
|
||||
|
||||
private function getDriver()
|
||||
{
|
||||
return new AnnotationDriver(new AnnotationReader());
|
||||
}
|
||||
}
|
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Metadata\Driver\Fixture;
|
||||
|
||||
use Security\SecurityContext;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use JMS\DiExtraBundle as DI; // Use this alias in order to not have this class picked up by the finder
|
||||
|
||||
/**
|
||||
* @DI\Annotation\FormType
|
||||
*
|
||||
* @author Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*/
|
||||
class LoginType extends AbstractType
|
||||
{
|
||||
private $securityContext;
|
||||
|
||||
public function __construct(SecurityContext $context)
|
||||
{
|
||||
$this->securityContext = $context;
|
||||
}
|
||||
|
||||
public function getName()
|
||||
{
|
||||
return 'login';
|
||||
}
|
||||
}
|
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests\Metadata\Driver\Fixture;
|
||||
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use JMS\DiExtraBundle as DI;
|
||||
|
||||
/**
|
||||
* @DI\Annotation\FormType("foo")
|
||||
*
|
||||
* @author johannes
|
||||
*/
|
||||
class SignUpType extends AbstractType
|
||||
{
|
||||
public function getName()
|
||||
{
|
||||
return 'sign_up';
|
||||
}
|
||||
}
|
@@ -0,0 +1,100 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2011 Johannes M. Schmitt <schmittjoh@gmail.com>
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
namespace JMS\DiExtraBundle\Tests;
|
||||
|
||||
use Symfony\Bundle\TwigBundle\TwigBundle;
|
||||
use Symfony\Bundle\DoctrineBundle\DoctrineBundle;
|
||||
use JMS\DiExtraBundle\JMSDiExtraBundle;
|
||||
use JMS\SecurityExtraBundle\JMSSecurityExtraBundle;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\DependencyInjection\FrameworkExtension;
|
||||
use Symfony\Bundle\AsseticBundle\AsseticBundle;
|
||||
use Symfony\Bundle\MonologBundle\MonologBundle;
|
||||
use Symfony\Bundle\SecurityBundle\SecurityBundle;
|
||||
use Symfony\Bundle\FrameworkBundle\FrameworkBundle;
|
||||
use JMS\DiExtraBundle\Finder\ServiceFinder;
|
||||
|
||||
/**
|
||||
* @group performance
|
||||
*/
|
||||
class PerformanceTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* @dataProvider getFinderMethods
|
||||
*/
|
||||
public function testServiceFinder($method)
|
||||
{
|
||||
$finder = new ServiceFinder();
|
||||
$ref = new \ReflectionMethod($finder, $method);
|
||||
$ref->setAccessible(true);
|
||||
|
||||
$bundles = array(
|
||||
new FrameworkBundle(),
|
||||
new SecurityBundle(),
|
||||
new MonologBundle(),
|
||||
new AsseticBundle(),
|
||||
new DoctrineBundle(),
|
||||
new TwigBundle(),
|
||||
new SensioFrameworkExtraBundle(),
|
||||
new JMSSecurityExtraBundle(),
|
||||
);
|
||||
$bundles = array_map(function($v) {
|
||||
return $v->getPath();
|
||||
}, $bundles);
|
||||
|
||||
$bundles[] = __DIR__.'/../';
|
||||
|
||||
$time = microtime(true);
|
||||
for ($i=0,$c=5; $i<$c; $i++) {
|
||||
$ref->invoke($finder, $bundles);
|
||||
}
|
||||
$time = microtime(true) - $time;
|
||||
$this->printResults('service finder ('.$method.')', $time, $c);
|
||||
}
|
||||
|
||||
public function getFinderMethods()
|
||||
{
|
||||
return array(
|
||||
array('findUsingGrep'),
|
||||
array('findUsingFinder'),
|
||||
);
|
||||
}
|
||||
|
||||
private function printResults($test, $time, $iterations)
|
||||
{
|
||||
if (0 == $iterations) {
|
||||
throw new InvalidArgumentException('$iterations cannot be zero.');
|
||||
}
|
||||
|
||||
$title = $test." results:\n";
|
||||
$iterationsText = sprintf("Iterations: %d\n", $iterations);
|
||||
$totalTime = sprintf("Total Time: %.3f s\n", $time);
|
||||
$iterationTime = sprintf("Time per iteration: %.3f ms\n", $time/$iterations * 1000);
|
||||
|
||||
$max = max(strlen($title), strlen($iterationTime)) - 1;
|
||||
|
||||
echo "\n".str_repeat('-', $max)."\n";
|
||||
echo $title;
|
||||
echo str_repeat('=', $max)."\n";
|
||||
echo $iterationsText;
|
||||
echo $totalTime;
|
||||
echo $iterationTime;
|
||||
echo str_repeat('-', $max)."\n";
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
// this file searches for the autoload file of your project, and includes it
|
||||
$dir = __DIR__;
|
||||
$lastDir = null;
|
||||
while (($dir = dirname($dir)) && $dir !== $lastDir) {
|
||||
$lastDir = $dir;
|
||||
|
||||
if (file_exists($file = $dir.'/app/bootstrap.php.cache')) {
|
||||
require_once $file;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('Could not locate the project\'s bootstrap.php.cache. If your bundle is not inside a project, you need to replace this bootstrap file.');
|
Reference in New Issue
Block a user