public function testWithArrayStorage() { $feature = new Enabler\Feature('secret-project', true, ['Enabler\\Filter\\Identifier' => ["userIds" => [1, 2, 3, 4, 5]]]); $identity = new Enabler\Identity(3); $enabler = new Enabler\Enabler(new Enabler\Storage\Memory(), $identity); $this->assertTrue($enabler->enabled('secret-project')); }
public function testWithWrongRange() { $feature = new Enabler\Feature("secret-project", true, ["Enabler\\Filter\\Date" => ["from" => new DateTime("2000-10-01"), "to" => new DateTime("2001-10-01")]]); $mockStorage = $this->getMockBuilder('Enabler\\Storage\\Storable')->getMock(); $mockStorage->expects($this->any())->method('get')->will($this->returnValue($feature)); $identity = new Enabler\Identity(10); $enabler = new Enabler\Enabler($mockStorage, $identity); $enabler->storage()->create($feature); $this->assertFalse($enabler->enabled('secret-project')); }
public function testCheckArrayOfIpsWorks() { $feature = new Enabler\Feature("Music", true, ["Enabler\\Filter\\Ip" => array("127.0.2.1", "192.23.12.10")]); $mockStorage = $this->getMockBuilder('Enabler\\Storage\\Storable')->getMock(); $mockStorage->expects($this->any())->method('get')->will($this->returnValue($feature)); $enabler = new Enabler\Enabler($mockStorage); $enabler->storage()->create($feature); $_SERVER['REMOTE_ADDR'] = "127.0.2.2"; $this->assertEquals(false, $enabler->enabled('Music')); $_SERVER['REMOTE_ADDR'] = "192.23.12.10"; $this->assertEquals(true, $enabler->enabled('Music')); $_SERVER['REMOTE_ADDR'] = "127.0.2.1"; $this->assertEquals(true, $enabler->enabled('Music')); }
public function testMixingUserIdsAndGroups() { $feature = new Enabler\Feature("secret-project", true, ["Enabler\\Filter\\Identifier" => ["groups" => ["test", "early-adopters", "God"]], "Enabler\\Filter\\Identifier" => ["userIds" => [1, 2, 3, 10, 34, 54, 65, 24, 543, 564645, 23, 432, 54, 656]]]); $mockStorage = $this->getMockBuilder('Enabler\\Storage\\Storable')->getMock(); $mockStorage->expects($this->any())->method('get')->will($this->returnValue($feature)); $identity = new Enabler\Identity(10, "early-adopters"); $enabler = new Enabler\Enabler($mockStorage, $identity); $enabler->storage()->create($feature); $this->assertEquals(true, $enabler->enabled("secret-project")); $identity->setUserId(13); $identity->setGroup("Nobody"); $this->assertEquals(false, $enabler->enabled("secret-project")); $identity->setUserId(24); $identity->setGroup("Nobody"); $this->assertEquals(true, $enabler->enabled("secret-project")); }
public function testWith1Percent() { $percentage = 1; $feature = new Enabler\Feature("Music", true, ["Enabler\\Filter\\Distributed" => [$percentage]]); $mockStorage = $this->getMockBuilder('Enabler\\Storage\\Storable')->getMock(); $mockStorage->expects($this->any())->method('get')->will($this->returnValue($feature)); $enabler = new Enabler\Enabler($mockStorage); $enabler->storage()->create($feature); $numEnables = 0; for ($i = 0; $i <= 10000; $i++) { if ($enabler->enabled('Music')) { $numEnables++; } } $result = $numEnables - $numEnables <= $percentage ? true : false; $this->assertTrue($result); }
public function testWithDistributedAndIdentity() { $percentage = 10; $feature = new Enabler\Feature("secret-project", true, ["Enabler\\Filter\\Identifier" => ["userIds" => [1, 2, 3, 10, 34, 54, 65, 24, 543, 564645, 23, 432, 54, 656]], "Enabler\\Filter\\Distributed" => [$percentage]]); $mockStorage = $this->getMockBuilder('Enabler\\Storage\\Storable')->getMock(); $mockStorage->expects($this->any())->method('get')->will($this->returnValue($feature)); $identity = new Enabler\Identity(10); $enabler = new Enabler\Enabler($mockStorage, $identity); $enabler->storage()->create($feature); $numEnables = 0; for ($i = 0; $i <= 10000; $i++) { if ($enabler->enabled('secret-project')) { $numEnables++; } } $result = $numEnables - $numEnables <= $percentage ? true : false; $this->assertTrue($result); }