Skip to content

Commit

Permalink
Update package to use PSR-4
Browse files Browse the repository at this point in the history
  • Loading branch information
Webonaute authored and rdohms committed Jul 13, 2018
1 parent 1fc20c4 commit 930708d
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 33 deletions.
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -24,8 +24,8 @@
},

"autoload": {
"psr-0": {
"DMS": "src"
"psr-4": {
"DMS\\Bundle\\FilterBundle\\": "./src/DMS/Bundle/FilterBundle"
}
}
}
15 changes: 9 additions & 6 deletions phpunit.xml
Expand Up @@ -3,14 +3,17 @@

<testsuites>
<testsuite name="DMS Filter Bundle">
<directory>src</directory>
<directory>./src/DMS/Bundle/FilterBundle/Tests/</directory>
</testsuite>
</testsuites>

<filter>
<blacklist>
<directory>src/DMS/Bundle/FilterBundle/Tests</directory>
<directory>vendor</directory>
</blacklist>
<whitelist>
<directory>./src</directory>
<exclude>
<directory>./src/DMS/Bundle/FilterBundle/Tests</directory>
<directory>./src/DMS/Bundle/FilterBundle/Resources</directory>
</exclude>
</whitelist>
</filter>
</phpunit>
</phpunit>
13 changes: 8 additions & 5 deletions src/DMS/Bundle/FilterBundle/Tests/AnnotationLoadingTest.php
Expand Up @@ -10,6 +10,9 @@
use Doctrine\Common\Annotations\AnnotationReader;
use Doctrine\Common\Annotations\AnnotationRegistry;
use PHPUnit\Framework\TestCase;
use DMS\Bundle\FilterBundle\Tests\Dummy\AnnotatedClass;
use DMS\Bundle\FilterBundle\Rule\Service;
use DMS\Filter\Rules\Alpha;

class AnnotationLoadingTest extends TestCase
{
Expand Down Expand Up @@ -40,12 +43,12 @@ protected function setUp()

public function testRuleLoader()
{
$metadata = $this->factory->getClassMetadata('DMS\Bundle\FilterBundle\Tests\Dummy\AnnotatedClass');
$metadata = $this->factory->getClassMetadata(AnnotatedClass::class);

$this->assertRules(2, array('DMS\Filter\Rules\StripTags', 'DMS\Filter\Rules\Alpha'), $metadata->getPropertyRules('name'));
$this->assertRules(1, array('DMS\Filter\Rules\StripTags'), $metadata->getPropertyRules('nickname'));
$this->assertRules(1, array('DMS\Filter\Rules\StripTags'), $metadata->getPropertyRules('description'));
$this->assertRules(1, array('DMS\Bundle\FilterBundle\Rule\Service'), $metadata->getPropertyRules('serviceFiltered'));
$this->assertRules(2, array(StripTags::class, Alpha::class), $metadata->getPropertyRules('name'));
$this->assertRules(1, array(StripTags::class), $metadata->getPropertyRules('nickname'));
$this->assertRules(1, array(StripTags::class), $metadata->getPropertyRules('description'));
$this->assertRules(1, array(Service::class), $metadata->getPropertyRules('serviceFiltered'));

$rules = $metadata->getPropertyRules('description');

Expand Down
Expand Up @@ -12,6 +12,9 @@
use Symfony\Component\Form\FormEvents;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\PropertyAccess\PropertyPath;
use Symfony\Component\Form\FormConfigInterface;
use Symfony\Component\Form\Test\FormInterface;
use Symfony\Component\EventDispatcher\Event;

class DelegatingFilterListenerTest extends TestCase
{
Expand Down Expand Up @@ -47,15 +50,15 @@ class DelegatingFilterListenerTest extends TestCase

protected function setUp()
{
if (!class_exists('Symfony\Component\EventDispatcher\Event')) {
if (!class_exists(Event::class)) {
$this->markTestSkipped('The "EventDispatcher" component is not available');
}

$this->dispatcher = $this->getMockBuilder('Symfony\Component\EventDispatcher\EventDispatcherInterface')
$this->dispatcher = $this->getMockBuilder(EventDispatcherInterface::class)
->getMock();
$this->factory = $this->getMockBuilder('Symfony\Component\Form\FormFactoryInterface')
$this->factory = $this->getMockBuilder(FormFactoryInterface::class)
->getMock();
$this->delegate = $this->getMockBuilder('DMS\Bundle\FilterBundle\Service\Filter')
$this->delegate = $this->getMockBuilder(Filter::class)
->disableOriginalConstructor()
->getMock();
$this->listener = new DelegatingFilterListener($this->delegate);
Expand All @@ -81,15 +84,15 @@ protected function getForm($name = 'name', $propertyPath = null)

protected function getMockForm()
{
return $this->getMockBuilder('Symfony\Component\Form\Test\FormInterface')
return $this->getMockBuilder(FormInterface::class)
->getMock();
}

public function testFilterIgnoresNonRootWithCascadeOff()
{
$form = $this->getMockForm();
$parentForm = $this->getMockForm();
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')
$config = $this->getMockBuilder(FormConfigInterface::class)
->getMock();

$form->expects($this->exactly(2))
Expand Down Expand Up @@ -126,7 +129,7 @@ public function testFilterFiltersNonRootWithCascadeOn()
$entity = new AnnotatedClass();
$form = $this->getMockForm();
$parentForm = $this->getMockForm();
$config = $this->getMockBuilder('Symfony\Component\Form\FormConfigInterface')
$config = $this->getMockBuilder(FormConfigInterface::class)
->getMock();

$form->expects($this->exactly(2))
Expand Down
Expand Up @@ -4,6 +4,7 @@
namespace DMS\Bundle\FilterBundle\Tests\Loader;

use DMS\Bundle\FilterBundle\Loader\ContainerAwareLoader;
use DMS\Filter\Filters\StripTags as StripTagsFilter;
use DMS\Filter\Rules\StripTags;
use PHPUnit\Framework\TestCase;
use Symfony\Component\DependencyInjection\ContainerInterface;
Expand All @@ -20,25 +21,14 @@ class ContainerAwareLoaderTest extends TestCase
*/
protected $loader;

protected function setUp()
{
parent::setUp();

$this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')
->getMock();

$this->loader = new ContainerAwareLoader();
$this->loader->setContainer($this->container);
}

public function testGetFilterForRule()
{
$this->container->expects($this->once())->method('has')->will($this->returnValue(true));
$this->container->expects($this->once())->method('get')->will($this->returnValue(new \stdClass()));

$filter = $this->loader->getFilterForRule(new StripTags());

$this->assertInstanceOf('\stdClass', $filter);
$this->assertInstanceOf(\stdClass::class, $filter);
}

public function testGetFilterForRuleCascade()
Expand All @@ -48,6 +38,17 @@ public function testGetFilterForRuleCascade()

$filter = $this->loader->getFilterForRule(new StripTags());

$this->assertInstanceOf('\DMS\Filter\Filters\StripTags', $filter);
$this->assertInstanceOf(StripTagsFilter::class, $filter);
}

protected function setUp()
{
parent::setUp();

$this->container = $this->getMockBuilder(ContainerInterface::class)
->getMock();

$this->loader = new ContainerAwareLoader();
$this->loader->setContainer($this->container);
}
}

0 comments on commit 930708d

Please sign in to comment.