Skip to content
This repository has been archived by the owner on May 1, 2019. It is now read-only.

Commit

Permalink
Merge pull request #366 from localheinz/fix/entity-test
Browse files Browse the repository at this point in the history
Fix: Entity test
  • Loading branch information
Ocramius committed Feb 6, 2015
2 parents a8c4db1 + 11f7c24 commit 592d6d1
Show file tree
Hide file tree
Showing 2 changed files with 78 additions and 35 deletions.
30 changes: 16 additions & 14 deletions module/ZfModule/src/ZfModule/Entity/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,47 +2,49 @@

namespace ZfModule\Entity;

use DateTime;

class Module implements ModuleInterface
{
/**
* @var id
* @var int
*/
protected $id = null;
private $id;

/**
* @var string
*/
protected $name = null;
private $name;

/**
* @var string
*/
protected $description = null;
private $description;

/**
* @var string
*/
protected $url = null;
private $url;

/**
* @var int
* @var string
*/
protected $createdAt = null;
private $createdAt;

/**
* @var int
* @var string
*/
protected $updatedAt = null;
private $updatedAt;

/**
* @var string
*/
protected $owner = null;
private $owner;

/**
* @var string
*/
protected $photoUrl = null;
private $photoUrl;

public function getPhotoUrl()
{
Expand Down Expand Up @@ -86,11 +88,11 @@ public function getCreatedAt()
}

/**
* @return \DateTime
* @return DateTime
*/
public function getCreateAtDateTime()
public function getCreatedAtDateTime()
{
return new \DateTime($this->getCreatedAt());
return new DateTime($this->getCreatedAt());
}

public function setCreatedAt($createdAt)
Expand Down
83 changes: 62 additions & 21 deletions module/ZfModule/test/ZfModuleTest/Entity/ModuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,76 +2,117 @@

namespace ZfModuleTest\Entity;

use DateTime;
use PHPUnit_Framework_TestCase;
use ZfModule\Entity\Module;
use ZfModule\Entity;

class ModuleTest extends PHPUnit_Framework_TestCase
{
protected $module;
/**
* @var Entity\Module
*/
private $module;

public function setUp()
{
$this->module = new Module();
$this->module = new Entity\Module();
}

public function testModuleConstruction()
public function testDefaults()
{
$this->assertInstanceOf('ZfModule\Entity\Module', $this->module);
$this->assertNull($this->module->getId());
$this->assertNull($this->module->getName());
$this->assertNull($this->module->getDescription());
$this->assertNull($this->module->getOwner());
$this->assertNull($this->module->getPhotoUrl());
$this->assertNull($this->module->getUrl());
$this->assertEquals(new DateTime(), $this->module->getCreatedAtDateTime());
$this->assertNull($this->module->getCreatedAt());
$this->assertNull($this->module->getUpdatedAt());
}

public function testFluentInterface()
{
$this->assertSame($this->module, $this->module->setId(9000));
$this->assertSame($this->module, $this->module->setName('foo'));
$this->assertSame($this->module, $this->module->setDescription('bar'));
$this->assertSame($this->module, $this->module->setOwner('John Doe'));
$this->assertSame($this->module, $this->module->setPhotoUrl('http://www.example.com/photo.jpg'));
$this->assertSame($this->module, $this->module->setUrl('http://www.example.com'));
$this->assertSame($this->module, $this->module->setCreatedAt('2013-02-28 13:05:00'));
$this->assertSame($this->module, $this->module->setUpdatedAt('2013-02-28 13:05:00'));
}

public function testSetOwner()
{
$this->module->setOwner('johndoe');
$owner = 'johndoe';

$this->assertEquals('johndoe', $this->module->getOwner());
$this->module->setOwner($owner);

$this->assertSame($owner, $this->module->getOwner());
}

public function testSetId()
{
$this->module->setId(99);
$id = 99;

$this->module->setId($id);

$this->assertEquals(99, $this->module->getId());
$this->assertSame($id, $this->module->getId());
}

public function testSetUrl()
{
$this->module->setUrl('http://example.com');
$url = 'http://example.com';

$this->module->setUrl($url);

$this->assertEquals('http://example.com', $this->module->getUrl());
$this->assertSame($url, $this->module->getUrl());
}

public function testSetName()
{
$this->module->setName('Super Great Happy Good Time Module');
$name = 'Super Great Happy Good Time Module';

$this->assertEquals('Super Great Happy Good Time Module', $this->module->getName());
$this->module->setName($name);

$this->assertSame($name, $this->module->getName());
}

public function testSetDescription()
{
$this->module->setDescription('Lorem ipsum dolor sit amet');
$description = 'Lorem ipsum dolor sit amet';

$this->module->setDescription($description);

$this->assertEquals('Lorem ipsum dolor sit amet', $this->module->getDescription());
$this->assertSame($description, $this->module->getDescription());
}

public function testSetCreatedAt()
{
$this->module->setCreatedAt('2013-02-28 13:05:00');
$createdAt = '2013-02-28 13:05:00';

$this->module->setCreatedAt($createdAt);

$this->assertEquals('2013-02-28 13:05:00', $this->module->getCreatedAt());
$this->assertSame($createdAt, $this->module->getCreatedAt());
$this->assertEquals(new DateTime($createdAt), $this->module->getCreatedAtDateTime());
}

public function testSetUpdatedAt()
{
$this->module->setUpdatedAt('2013-02-28 13:05:00');
$updatedAt = '2013-02-28 13:05:00';

$this->assertEquals('2013-02-28 13:05:00', $this->module->getUpdatedAt());
$this->module->setUpdatedAt($updatedAt);

$this->assertSame($updatedAt, $this->module->getUpdatedAt());
}

public function testSetPhotoUrl()
{
$this->module->setPhotoUrl('http://www.example.com/photo.jpg');
$photoUrl = 'http://www.example.com/photo.jpg';

$this->module->setPhotoUrl($photoUrl);

$this->assertEquals('http://www.example.com/photo.jpg', $this->module->getPhotoUrl());
$this->assertSame($photoUrl, $this->module->getPhotoUrl());
}
}

0 comments on commit 592d6d1

Please sign in to comment.