Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
194 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...s/fr/adrienbrault/idea/symfony2plugin/tests/config/EventDispatcherSubscriberUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.tests.config; | ||
|
||
import fr.adrienbrault.idea.symfony2plugin.config.EventDispatcherSubscriberUtil; | ||
import fr.adrienbrault.idea.symfony2plugin.config.dic.EventDispatcherSubscribedEvent; | ||
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class EventDispatcherSubscriberUtilTest extends SymfonyLightCodeInsightFixtureTestCase { | ||
|
||
public void setUp() throws Exception { | ||
super.setUp(); | ||
myFixture.copyFileToProject("EventSubscriber.php"); | ||
} | ||
|
||
public String getTestDataPath() { | ||
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath(); | ||
} | ||
|
||
/** | ||
* @see EventDispatcherSubscriberUtil#getSubscribedEvents | ||
* @see EventDispatcherSubscriberUtil#attachSubscriberEventNames | ||
*/ | ||
public void testGetSubscribedEvent() { | ||
EventDispatcherSubscribedEvent event1 = EventDispatcherSubscriberUtil.getSubscribedEvent(getProject(), "pre.foo").get(0); | ||
assertEquals("pre.foo", event1.getStringValue()); | ||
assertEquals("TestEventSubscriber", event1.getFqnClassName()); | ||
assertNull(event1.getSignature()); | ||
assertEquals("preFoo", event1.getMethodName()); | ||
|
||
EventDispatcherSubscribedEvent event2 = EventDispatcherSubscriberUtil.getSubscribedEvent(getProject(), "post.foo").get(0); | ||
assertEquals("post.foo", event2.getStringValue()); | ||
assertEquals("TestEventSubscriber", event2.getFqnClassName()); | ||
assertEquals("#K#C\\Foo\\Bar.BAR", event2.getSignature()); | ||
assertEquals("postFoo", event2.getMethodName()); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
tests/fr/adrienbrault/idea/symfony2plugin/tests/config/fixtures/EventSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
namespace Foo { | ||
class Bar { | ||
const BAR = 'post.foo'; | ||
} | ||
} | ||
|
||
namespace Symfony\Component\EventDispatcher { | ||
interface EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(); | ||
} | ||
} | ||
|
||
namespace { | ||
|
||
use Foo\Bar; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class TestEventSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
'pre.foo' => 'preFoo', | ||
Bar::BAR => 'postFoo' | ||
); | ||
} | ||
|
||
public function preFoo() {} | ||
public function postFoo() {} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/fr/adrienbrault/idea/symfony2plugin/tests/util/EventSubscriberUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package fr.adrienbrault.idea.symfony2plugin.tests.util; | ||
|
||
import fr.adrienbrault.idea.symfony2plugin.tests.SymfonyLightCodeInsightFixtureTestCase; | ||
import fr.adrienbrault.idea.symfony2plugin.util.EventSubscriberUtil; | ||
|
||
import java.io.File; | ||
|
||
/** | ||
* @author Daniel Espendiller <daniel@espendiller.net> | ||
*/ | ||
public class EventSubscriberUtilTest extends SymfonyLightCodeInsightFixtureTestCase { | ||
|
||
public void setUp() throws Exception { | ||
super.setUp(); | ||
myFixture.copyFileToProject("EventSubscriber.php"); | ||
} | ||
|
||
public String getTestDataPath() { | ||
return new File(this.getClass().getResource("fixtures").getFile()).getAbsolutePath(); | ||
} | ||
|
||
/** | ||
* @see EventSubscriberUtil#getTaggedEventMethodParameter | ||
*/ | ||
public void testGetTaggedEventMethodParameterWithInternals() { | ||
assertEquals("\\Symfony\\Component\\HttpKernel\\Event\\GetResponseEvent", EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "kernel.request")); | ||
} | ||
|
||
/** | ||
* @see EventSubscriberUtil#getTaggedEventMethodParameter | ||
*/ | ||
public void testGetTaggedEventMethodParameterWithSubscriberInterface() { | ||
assertEquals("\\DateTime", EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "pre.foo")); | ||
assertNull(EventSubscriberUtil.getTaggedEventMethodParameter(getProject(), "pre.foo_doh")); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
tests/fr/adrienbrault/idea/symfony2plugin/tests/util/fixtures/EventSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
namespace Symfony\Component\EventDispatcher { | ||
interface EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents(); | ||
} | ||
} | ||
|
||
namespace { | ||
|
||
use Foo\Bar; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
class TestDateTimeEventSubscriber implements EventSubscriberInterface | ||
{ | ||
public static function getSubscribedEvents() | ||
{ | ||
return array( | ||
'pre.foo' => 'preFoo', | ||
'kernel.request' => 'FOO', | ||
); | ||
} | ||
|
||
public function preFoo(\DateTime $d) {} | ||
} | ||
} |