for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
<?php
namespace WebOfTalent\PrevNextSibling\Tests;
use SilverStripe\Dev\SapphireTest;
class PrevNextSiblingExtensionTest extends SapphireTest {
protected static $fixture_file = 'tests/PrevNextSiblingExtensionTest.yml';
public function testNextSibling() {
$child1 = $this->objFromFixture('Page', 'child01');
$child2 = $this->objFromFixture('Page', 'child02');
$child3 = $this->objFromFixture('Page', 'child03');
$this->assertNull($child3->NextSibling());
$this->assertEquals($child2->ID, $child1->NextSibling()->ID);
$this->assertEquals($child3->ID, $child2->NextSibling()->ID);
}
public function testPreviousSibling() {
$this->assertNull($child1->PreviousSibling());
$this->assertEquals($child1->ID, $child2->PreviousSibling()->ID);
$this->assertEquals($child2->ID, $child3->PreviousSibling()->ID);