Skip to content

Commit

Permalink
change @ExpectedException over setExpectedException
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Jul 22, 2017
1 parent a8767d7 commit fb6b341
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 11 deletions.
4 changes: 3 additions & 1 deletion tests/AssistedTest.php
Expand Up @@ -57,9 +57,11 @@ public function testAssistedMethodInvocation()
$this->assertSame(1, $db->dbId);
}

/**
* @expectedException \Ray\Di\Exception\MethodInvocationNotAvailable
*/
public function testAssistedMethodInvocationNotAvailable()
{
$this->setExpectedException(MethodInvocationNotAvailable::class);
$assistedDbProvider = (new Injector(new FakeAssistedDbModule))->getInstance(FakeAssistedDbProvider::class);
/* @var $assistedDbProvider FakeAssistedDbProvider */
$assistedDbProvider->get();
Expand Down
20 changes: 15 additions & 5 deletions tests/BindTest.php
Expand Up @@ -31,21 +31,27 @@ public function testToString()
$this->assertSame('Ray\Di\FakeTyreInterface-' . NAME::ANY, (string) $this->bind);
}

/**
* @expectedException \Ray\Di\Exception\Notfound
*/
public function testInvalidToTest()
{
$this->setExpectedException(Notfound::class);
$this->bind->to('invalid-class');
}

/**
* @expectedException \Ray\Di\Exception\Notfound
*/
public function testInvalidToProviderTest()
{
$this->setExpectedException(Notfound::class);
$this->bind->toProvider('invalid-class');
}

/**
* @expectedException \Ray\Di\Exception\NotFound
*/
public function testInValidInterfaceBinding()
{
$this->setExpectedException(NotFound::class);
new Bind(new Container, 'invalid-interface');
}

Expand Down Expand Up @@ -98,15 +104,19 @@ public function testToConstructorWithMethodInjection()
$this->assertInstanceOf(FakeEngine::class, $instance->engine);
}

/**
* @expectedException \Ray\Di\Exception\InvalidType
*/
public function testToValidation()
{
$this->setExpectedException(InvalidType::class);
(new Bind(new Container, FakeHandleInterface::class))->to(FakeEngine::class);
}

/**
* @expectedException \Ray\Di\Exception\InvalidProvider
*/
public function testToProvider()
{
$this->setExpectedException(InvalidProvider::class);
(new Bind(new Container, FakeHandleInterface::class))->toProvider(FakeEngine::class);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/ContainerTest.php
Expand Up @@ -120,9 +120,11 @@ public function testMove()
$this->assertInstanceOf(FakeEngine::class, $instance);
}

/**
* @expectedException \Ray\Di\Exception\Unbound
*/
public function testMoveUnbound()
{
$this->setExpectedException(Unbound::class);
$this->container->move(FakeEngineInterface::class, 'invalid', FakeEngineInterface::class, 'new');
}

Expand Down
8 changes: 6 additions & 2 deletions tests/InjectorTest.php
Expand Up @@ -26,9 +26,11 @@ public function testToInstance()
$this->assertSame($engine, $injector->getInstance(FakeEngine::class));
}

/**
* @expectedException \Ray\Di\Exception\Unbound
*/
public function testUnbound()
{
$this->setExpectedException(Unbound::class);
$injector = new Injector(new FakeInstanceBindModule);
$injector->getInstance('', 'invalid-binding-xxx');
}
Expand Down Expand Up @@ -274,9 +276,11 @@ public function testContextualDependencyInjection()
$this->assertInstanceOf(FakeRightLeg::class, $robot->rightLeg);
}

/**
* @expectedException \Ray\Di\Exception\Unbound
*/
public function testNewAbstract()
{
$this->setExpectedException(Unbound::class, FakeAbstractClass::class);
(new Injector)->getInstance(FakeConcreteClass::class);
}

Expand Down
4 changes: 3 additions & 1 deletion tests/ModuleTest.php
Expand Up @@ -18,9 +18,11 @@ public function testInstall()
$this->assertInstanceOf(AbstractModule::class, $module);
}

/**
* @expectedException \Ray\Di\Exception\NotFound
*/
public function testToInvalidClass()
{
$this->setExpectedException(NotFound::class);
new FakeToBindInvalidClassModule;
}

Expand Down
4 changes: 3 additions & 1 deletion tests/SetterMethodTest.php
Expand Up @@ -30,9 +30,11 @@ public function testInvoke()
$this->assertNotSame(spl_object_hash($car->frontTyre), spl_object_hash($car->rearTyre));
}

/**
* @expectedException \Ray\Di\Exception\Unbound
*/
public function testUnbound()
{
$this->setExpectedException(Unbound::class);
$container = new Container;
$car = new FakeCar(new FakeEngine);
$this->setterMethods->__invoke($car, $container);
Expand Down

0 comments on commit fb6b341

Please sign in to comment.