Zvonimir Spajic
<?php
class Bartender {
// ...
public function serveDrink(Customer $customer) {
if ($customer->age < 18){
throw \Exception('Not allowed to drink');
}
// ...
}
}
<?php
class Bartender {
// ...
public function serveDrink(Customer $customer) {
if ($customer->age > 18){
throw \Exception('Not allowed to drink');
}
// ...
}
}
<?php
class Bartender {
// ...
public function serveDrink(Customer $customer) {
if ($customer->age > 18){
throw \Exception('Not allowed to drink');
}
// ...
}
}
<?php
class BartenderTest {
// ...
public function test_it_does_not_serve_customer_under_age_18() {
$customer = new Customer(10);
$bartender = new Bartender();
$this->exceptException(\Exception::class);
$bartender->serve($customer);
}
}
<?php
class BartenderTest {
// ...
public function test_it_does_not_serve_customer_under_age_18() {
$customer = new Customer(18);
$bartender = new Bartender();
$this->exceptException(\Exception::class);
$bartender->serve($customer);
}
}
<?php
public function hasErrors(): bool
{
return count($this->errors) > 0;
}