Skip to content

Commit

Permalink
Added test for correct exception being thrown when a listener / subsc…
Browse files Browse the repository at this point in the history
…riber cannot be resolved from the container
  • Loading branch information
maxbrokman committed Sep 23, 2015
1 parent f314857 commit 8d38ff4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EntityManagerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ protected function registerListeners($settings = [], EntityManagerInterface $man
}
}
}

/**
* @param string $event
* @param string|string[] $listener
Expand Down
48 changes: 48 additions & 0 deletions tests/EntityManagerFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,30 @@ public function test_can_set_multiple_listeners()
$this->assertCount(2, $manager->getEventManager()->getListeners('name'));
}

public function test_setting_non_existent_listener_throws_exception()
{
$reflectionException = new ReflectionException();

$this->container->shouldReceive('make')
->with('ClassDoesNotExist')
->once()
->andThrow($reflectionException);

$this->setExpectedException(InvalidArgumentException::class);

$this->disableDebugbar();
$this->disableSecondLevelCaching();
$this->disableCustomCacheNamespace();
$this->disableCustomFunctions();
$this->enableLaravelNamingStrategy();

$this->settings['events']['listeners'] = [
'name' => 'ClassDoesNotExist'
];

$this->factory->create($this->settings);
}

public function test_can_set_subscribers()
{
$this->container->shouldReceive('make')
Expand All @@ -350,6 +374,30 @@ public function test_can_set_subscribers()
$this->assertTrue(array_key_exists('onFlush', $manager->getEventManager()->getListeners()));
}

public function test_setting_non_existent_subscriber_throws_exception()
{
$reflectionException = new ReflectionException();

$this->container->shouldReceive('make')
->with('ClassDoesNotExist')
->once()
->andThrow($reflectionException);

$this->setExpectedException(InvalidArgumentException::class);

$this->disableDebugbar();
$this->disableSecondLevelCaching();
$this->disableCustomCacheNamespace();
$this->disableCustomFunctions();
$this->enableLaravelNamingStrategy();

$this->settings['events']['subscribers'] = [
'name' => 'ClassDoesNotExist'
];

$this->factory->create($this->settings);
}

public function test_can_set_custom_naming_strategy()
{
$this->disableDebugbar();
Expand Down

0 comments on commit 8d38ff4

Please sign in to comment.