Skip to content

Commit

Permalink
Completed base testing
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Salter committed Jan 25, 2016
1 parent 695ec35 commit dd2050b
Show file tree
Hide file tree
Showing 9 changed files with 325 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Item/Type/PermissionItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function setItem(ItemInterface $item) : PermissionItem
*/
public function isAllowed() : bool
{
return $this->allowed;
return $this->allowed ? true : false;
}

/**
Expand Down
29 changes: 29 additions & 0 deletions src/Item/Type/UserItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ class UserItem extends AbstractItem implements SimpleTypeInterface
*/
private $userGroupId;

/**
* UserItem constructor.
*/
public function __construct()
{
$this->assignId(self::ID_PREFIX);
Expand All @@ -59,6 +62,9 @@ public function setFirstName(string $firstName)
return $this;
}

/**
* @return bool
*/
public function hasFirstName() : bool
{
return $this->firstName !== null;
Expand All @@ -85,6 +91,9 @@ public function setSurname(string $surname) : UserItem
return $this;
}

/**
* @return bool
*/
public function hasSurname() : bool
{
return $this->surname !== null;
Expand All @@ -111,11 +120,27 @@ public function setUserGroupId(string $userGroupId) : UserItem
return $this;
}

/**
* @param UserGroupItem $userGroup
* @return UserItem
*/
public function setUserGroup(UserGroupItem $userGroup) : UserItem
{
$this->setUserGroupId($userGroup->getId());
return $this;
}

/**
* @return bool
*/
public function hasUserGroupId() : bool
{
return $this->userGroupId !== null;
}

/**
* @return array
*/
public function toArray() : array
{
return array_merge([
Expand All @@ -125,6 +150,10 @@ public function toArray() : array
], parent::toArray());
}

/**
* @param array $data
* @return ItemInterface
*/
public function fromArray(array $data) : ItemInterface
{
parent::fromArray($data);
Expand Down
26 changes: 26 additions & 0 deletions test/Item/ItemFactoryEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
use Verona\Item\ItemFactoryEvent;
use Verona\Item\ItemInterface;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:36
*/
class ItemFactoryEventTest extends PHPUnit_Framework_TestCase
{

public function testGettersAndSetters()
{

$event = new ItemFactoryEvent();

$expectedItem = $this->getMock(ItemInterface::class);
$this->assertFalse($event->hasItem());
$this->assertInstanceOf(ItemFactoryEvent::class, $event->setItem($expectedItem));
$this->assertTrue($event->hasItem());
$this->assertEquals($expectedItem, $event->getItem());

}
}
67 changes: 67 additions & 0 deletions test/Item/Type/PermissionItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
use Verona\Item\Type\PermissionItem;
use Verona\Item\Type\UserGroupItem;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:15
*/
class PermissionItemTest extends PHPUnit_Framework_TestCase
{


/**
* @return PermissionItem
*/
public function testGettersAndSetters()
{

$permission = new PermissionItem();

$expectedItem = new PermissionItem();
$this->assertFalse($permission->hasItemId());
$this->assertInstanceOf(PermissionItem::class, $permission->setItem($expectedItem));
$this->assertEquals($expectedItem->getId(), $permission->getItemId());
$this->assertTrue($permission->hasItemId());
$this->assertInstanceOf(PermissionItem::class, $permission->setItemId($expectedItem->getId()));
$this->assertEquals($expectedItem->getId(), $permission->getItemId());

$expectedUserGroup = new UserGroupItem();
$this->assertFalse($permission->hasUserGroupId());
$this->assertInstanceOf(PermissionItem::class, $permission->setUserGroup($expectedUserGroup));
$this->assertEquals($expectedUserGroup->getId(), $permission->getUserGroupId());
$this->assertTrue($permission->hasUserGroupId());
$this->assertInstanceOf(PermissionItem::class, $permission->setUserGroupId($expectedUserGroup->getId()));
$this->assertEquals($expectedUserGroup->getId(), $permission->getUserGroupId());

$expectedAllowed = true;
$this->assertFalse($permission->isAllowed());
$this->assertInstanceOf(PermissionItem::class, $permission->setAllowed($expectedAllowed));
$this->assertEquals($expectedAllowed, $permission->isAllowed());

return $permission;

}

/**
* @param PermissionItem $item
* @depends testGettersAndSetters
*/
public function testExchangeable(PermissionItem $item)
{

$conf = $item->toArray();

$newItem = new PermissionItem();
$newItem->fromArray($conf);

$this->assertEquals($item, $newItem);

$newConf = $newItem->toArray();

$this->assertEquals($conf, $newConf);

}
}
49 changes: 49 additions & 0 deletions test/Item/Type/UserGroupItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
use Verona\Item\Type\UserGroupItem;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:23
*/
class UserGroupItemTest extends PHPUnit_Framework_TestCase
{

/**
* @return UserGroupItem
*/
public function testGettersAndSetters()
{

$userGroup = new UserGroupItem();

$expectedName = 'rawrderawr';
$this->assertInstanceOf(UserGroupItem::class, $userGroup->setName($expectedName));
$this->assertEquals($expectedName, $userGroup->getName());

return $userGroup;

}


/**
* @param UserGroupItem $userGroup
* @depends testGettersAndSetters
*/
public function testExchangeable(UserGroupItem $userGroup)
{

$conf = $userGroup->toArray();

$newUserGroup = new UserGroupItem();
$newUserGroup->fromArray($conf);

$this->assertEquals($userGroup, $newUserGroup);

$newConf = $newUserGroup->toArray();

$this->assertEquals($conf, $newConf);

}
}
67 changes: 67 additions & 0 deletions test/Item/Type/UserItemTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
use Verona\Item\Type\UserGroupItem;
use Verona\Item\Type\UserItem;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:27
*/
class UserItemTest extends PHPUnit_Framework_TestCase
{

/**
* @return UserItem
*/
public function testGettersAndSetters()
{

$user = new UserItem();

$expectedUserGroup = new UserGroupItem();
$this->assertFalse($user->hasUserGroupId());
$this->assertInstanceOf(UserItem::class, $user->setUserGroup($expectedUserGroup));
$this->assertTrue($user->hasUserGroupId());
$this->assertEquals($expectedUserGroup->getId(), $user->getUserGroupId());
$this->assertInstanceOf(UserItem::class, $user->setUserGroupId($expectedUserGroup->getId()));
$this->assertEquals($expectedUserGroup->getId(), $user->getUserGroupId());

$expectedName = 'Great';
$this->assertFalse($user->hasFirstName());
$this->assertInstanceOf(UserItem::class, $user->setFirstName($expectedName));
$this->assertTrue($user->hasFirstName());
$this->assertEquals($expectedName, $user->getFirstName());

$expectedSurname = 'Scott!';
$this->assertFalse($user->hasSurname());
$this->assertInstanceOf(UserItem::class, $user->setSurname($expectedSurname));
$this->assertTrue($user->hasSurname());
$this->assertEquals($expectedSurname, $user->getSurname());

return $user;

}

/**
* @param UserItem $user
* @depends testGettersAndSetters
*/
public function testExchangeable(UserItem $user)
{

$conf = $user->toArray();

$newUser = new UserItem();
$newUser->fromArray($conf);

$this->assertEquals($user, $newUser);

$newConf = $newUser->toArray();

$this->assertEquals($conf, $newConf);

}


}
25 changes: 25 additions & 0 deletions test/Timetable/TimetableManagerEventTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
use Verona\Timetable\TimetableManagerEvent;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:59
*/
class TimetableManagerEventTest extends PHPUnit_Framework_TestCase
{

public function testGettersAndSetters()
{

$event = new TimetableManagerEvent();

$expectedPointInTime = new DateTime();
$this->assertFalse($event->hasPointInTime());
$this->assertInstanceOf(TimetableManagerEvent::class, $event->setPointInTime($expectedPointInTime));
$this->assertTrue($event->hasPointInTime());
$this->assertEquals($expectedPointInTime, $event->getPointInTime());

}
}
38 changes: 38 additions & 0 deletions test/Value/AbstractEnumValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php
use Verona\Value\AbstractEnumValue;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:42
*/
class AbstractEnumValueTest extends PHPUnit_Framework_TestCase
{

public function testWithConstants()
{

$expectedA = 'A';
$expectedB = 'B';

/** @var AbstractEnumValue $class */
$class = (new class($expectedB) extends AbstractEnumValue {
const A = 'A';
const B = 'B';
});

$this->assertEquals($expectedB, $class->get());

try {
$class->set('FAIL');
$this->fail('Should not have reached this expression');
} catch (Exception $e) {}

$this->assertEquals([$expectedA, $expectedB], $class->getOptions());

$class->set($expectedA);
$this->assertEquals($expectedA, $class->get());

}
}
23 changes: 23 additions & 0 deletions test/Value/DateValueTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php
use Verona\Value\DateValue;

/**
* Created by PhpStorm.
* User: Nathan
* Date: 25/01/2016
* Time: 10:55
*/
class DateValueTest extends PHPUnit_Framework_TestCase
{


public function testOnlyDate()
{

$exampleOne = new DateValue('2015-01-01 10:15:32');
$exampleTwo = new DateValue('2015-01-01 15:15:15');

$this->assertEquals($exampleOne, $exampleTwo);

}
}

0 comments on commit dd2050b

Please sign in to comment.