DEV Community

Discussion on: Why You Must Always Follow Test to Break Principles

Collapse
 
chrisvasqm profile image
Christian Vasquez

Thanks for sharing this Rob!

The more I learn about TDD, the more I <3 it.

Side note: would you add js at the end of the first triple backticks for each code block? It makes them a little easier to read.

Without it:

private function validate(): void
{
    if ($this->car->getColour() !== 'black') {
        throw new OrderException('You must order a black car');
    }

    if ($this->car->getWheelCount() !== 4) {
        throw new OrderException('You must order a car with 4 wheels');
    }

    if ($this->car->getDoorCount() !== 5 && $this->car->getDoorCount() !== 3) {
        throw new OrderException('You must order a car with 5 or 3 doors');
    }
}

With it:

private function validate(): void
{
    if ($this->car->getColour() !== 'black') {
        throw new OrderException('You must order a black car');
    }

    if ($this->car->getWheelCount() !== 4) {
        throw new OrderException('You must order a car with 4 wheels');
    }

    if ($this->car->getDoorCount() !== 5 && $this->car->getDoorCount() !== 3) {
        throw new OrderException('You must order a car with 5 or 3 doors');
    }
}
Collapse
 
robdwaller profile image
Rob Waller

Thanks, the back tick thing is strange I noticed it but assumed that it was the styling for the site.

Normally I just put three back ticks followed by php. Maybe that doesn't work on this site. I'll update it to js.

Collapse
 
chrisvasqm profile image
Christian Vasquez

Ah yeah, I also tried using php but seems like is not supported yet.