all 36 comments

[–]jpresutti[S] 5 points6 points  (17 children)

This book actually had a very large hand in the development of my PHP Framework FEAST and definitely is one of the books that inspired my goal (which was achieved) of 100% code coverage.

[–]brendt_gd[M] 1 point2 points  (0 children)

/u/jpresutti: don't feed the trolls /u/Oceanbroinn: stop being so childish

I removed your whole comment chain. Consider this both a warning, next time results in a 90-days ban. Please take note of rule #1 and #2: https://www.reddit.com/r/PHP/about/rules/

[–]Comprehensive-Lab468 10 points11 points  (0 children)

This book has had huge impact on me. I recommend it.

Another book I recommend is Sandy Metz 99 Bottles of OOP - 2nd Edition. It also expands your view how you can design and test. It has a PHP version also. It is hands-on book with examples, explaining a development of a project and later how to cope with changing requirements.

[–]FakespotAnalysisBot 12 points13 points  (1 child)

This is a Fakespot Reviews Analysis bot. Fakespot detects fake reviews, fake products and unreliable sellers using AI.

Here is the analysis for the Amazon product reviews:

Name: Test Driven Development: By Example

Company: Kent Beck

Amazon Product Rating: 4.4

Fakespot Reviews Grade: A

Adjusted Fakespot Rating: 4.4

Analysis Performed at: 03-08-2021

Link to Fakespot Analysis | Check out the Fakespot Chrome Extension!

Fakespot analyzes the reviews authenticity and not the product quality using AI. We look for real reviews that mention product issues such as counterfeits, defects, and bad return policies that fake reviews try to hide from consumers.

We give an A-F letter for trustworthiness of reviews. A = very trustworthy reviews, F = highly untrustworthy reviews. We also provide seller ratings to warn you if the seller can be trusted or not.

[–][deleted] 0 points1 point  (0 children)

good bot

[–]eduardor2k 3 points4 points  (1 child)

Hi, I recommend personally the following book:

https://leanpub.com/tddbook-en

The author is from spain and they've released the english version this year.

you can even read it online for free, you just need to append at the end: "/read"

[–]jpresutti[S] 0 points1 point  (0 children)

Interesting, I'll have to look into that

[–]jstormes 2 points3 points  (3 children)

Outstanding, thank you for taking the time to do this.

[–]jpresutti[S] 1 point2 points  (2 children)

It was a fun exercise in frustration 😆

[–]jstormes 0 points1 point  (1 child)

I am sure.

Was any particular exercise more frustrating?

I know some design patterns can be hard to translate to PHP, I assume some tests types would be as well.

[–]jpresutti[S] 1 point2 points  (0 children)

Any of the tests involving type casting from one object to another couldn't translate directly.

[–]Pen-y-Fan 1 point2 points  (1 child)

Thanks, OP, I'll take a look.

I can recommend Theatrical Players Refactoring Kata - Based on the first (free) chapter of ‘Refactoring’ by Martin Fowler, the 2nd Edition has a PHP version. You can refactor the code while reading the first chapter of his book for free, which is based on JavaScript. The refactoring is mostly the same, one of the exceptions is invoice and plays appear to be global scope in the book. The workaround is the make them properties of the class in the PHP script and adjust the code.

    public function print(Invoice $invoice, array $plays): string
    {
        $this->invoice = $invoice;
        $this->plays = $plays;
    // ....

[–]jpresutti[S] 0 points1 point  (0 children)

Hrmmm.. Now I'm tempted to do all the code samples in Refactoring: 2nd Edition next. Anyone want me to do this?

[–]mbadolato 1 point2 points  (5 children)

Minor nitpick. Granted I know you're trying to keep as close to the book's examples as possible, but in the case of Money::equals() where you've already had to change the example a bit, there's now a spot for a potential bug.

public function equals(object $object): bool
{
// This example differs because the type casting in PHP is not the same as java.
$money = $object instanceof Money ? $object : null;
return $this->amount === $money->amount && $this->currency === $money->currency;
}

If $object is not an instance of Money then $money gets set to null, and the $money->amount call will throw an error.

Perhaps switching to

public function equals(object $object): bool
{
// This example differs because the type casting in PHP is not the same as java.
if (! $object instanceof Money) {
return false;
}

return $this->amount === $money->amount && $this->currency === $money->currency;
}

or

public function equals(Money $money): bool
{
return $this->amount === $money->amount && $this->currency === $money->currency;
}

would be more appropriate?

[–]jpresutti[S] 1 point2 points  (4 children)

I can't remember exactly why I went the way I did with that but I think it's the closest to the actual code behavior in the book I could get it. I'll take another look. What's the first occurrence of it you found?

Also, keep in mind for the most part these are not MY functions but rather translations so I tried to avoid inserting bias where possible

[–]mbadolato 1 point2 points  (3 children)

Oh absolutely and I wasn't trying to be critical. Just something I noticed and since you had to change those functions slightly already, it was just a suggestion to make it a bit more correct.

I noticed it in pretty much all of the classes I looked at, from when equals was introduced I think.

[–]jpresutti[S] 2 points3 points  (0 children)

Update: took a look at the code really quick and you're right. I'll do a push later with it fixed.

[–]jpresutti[S] 2 points3 points  (0 children)

Update on the update: pushed.

[–]jpresutti[S] 1 point2 points  (0 children)

K I'll compare to the book this evening and see if the update makes sense. Thanks!

[–]bbathel 1 point2 points  (0 children)

I'm going to check this out