phpspec

PHPSpec Catching TypeError in PHP7

偶尔善良 提交于 2019-12-05 04:12:40
I want test an example method with scalar type hinting and strict types in PHP7. When I don't pass an argument, the method should throw a TypeError . PHPSpec return fatal error: Uncaught TypeError: Argument 1 passed to Example::test <?php class Example { public function test(string $name) { $this->name = $name; } } class ExampleSpec extends ObjectBehavior { function it_is_initializable() { $this->shouldHaveType('Test\Example'); } function it_check_test_method_when_not_pass_argument() { $this->shouldThrow('\TypeError')->during('test'); } } At the beginning I declare: declare(strict_types=1);

First Shot at Testing Laravel 4 apps (PHPSpec/BDD vs. PHPUnit/TDD)

删除回忆录丶 提交于 2019-12-02 20:47:47
I have been wrestling with this question for far too long now. I know I need to just jump into one or the other since they are both obviously viable/useful tools, but have been stuck on the fence, researching both, for weeks. PHPUnit vs. PHPSpec - Which one may lead to better long-term maintainability and programming practices? I have talked to several seasoned PHPUnit -> PHPspec converts/users who now swear by PHPspec, claiming that it promotes better design thanks to its BDD approach. However, since it is a much newer tool there is a lack of community/tutorials in comparison with PHPUnit.

How to get property from stub function argument?

半世苍凉 提交于 2019-12-02 02:10:49
问题 I have a service, which should create an email class object and pass it to the third class (email-sender). I want to check body of email, which generates by the function. Service.php class Service { /** @var EmailService */ protected $emailService; public function __construct(EmailService $emailService) { $this->emailService = $emailService; } public function testFunc() { $email = new Email(); $email->setBody('abc'); // I want to test this attribute $this->emailService->send($email); } }

How to get property from stub function argument?

爷,独闯天下 提交于 2019-12-02 00:37:07
I have a service, which should create an email class object and pass it to the third class (email-sender). I want to check body of email, which generates by the function. Service.php class Service { /** @var EmailService */ protected $emailService; public function __construct(EmailService $emailService) { $this->emailService = $emailService; } public function testFunc() { $email = new Email(); $email->setBody('abc'); // I want to test this attribute $this->emailService->send($email); } } Email.php: class Email { protected $body; public function setBody($body) { $this->body = $body; } public