lundi 31 octobre 2016

Laravel Testing with PHPUnit assert correct order

I have defined a scope which sorty my entities by a published_at timestamp. I wanted to write a test to ensure correct ordering.

However I somehow fail to find a "nice" way to do this.

$novels = Novel::published()->get();

This is my best guess

for($i = 1; $i < count($novels); $i++) 
{
    $this->assertGreaterThanOrEqual(
        $novels->toArray()[$i - 1]['published_at'], 
        $novels->toArray()[$i]['published_at']
    );
}

Can anyone provide a better way ?

Aucun commentaire:

Enregistrer un commentaire