I am trying to check a try / catch block with a stub that throws an exception when a specific create method is called. It works fine, an exception is thrown, but instead of having his application catch it, it stops the test. What is the best way to do this.
<?php // TestCase $mockDao->expects($this->once()) ->method('create') ->will($this->throwException(new \Exception)); $service->addEntity($data); ?> <?php // Service public function addEntity($data) { .... try { ... $this->create($entity); // Test Halts with Exception ... } catch (Exception $e) { // Never Gets Called $this->handleException($e); } }
php phpunit
joeyadms
source share