mirror of
https://github.com/DesignPatternsPHP/DesignPatternsPHP.git
synced 2025-02-24 17:52:25 +01:00
making a unit test class with mockup instead of unfinished script
This commit is contained in:
parent
d9e5b562c4
commit
51fe7d477f
61
Tests/DataMapper/UserMapperTest.php
Normal file
61
Tests/DataMapper/UserMapperTest.php
Normal file
@ -0,0 +1,61 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* DesignPatternPHP
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace DesignPatterns\Test\DataMapper;
|
||||||
|
|
||||||
|
use DesignPatterns\DataMapper\UserMapper;
|
||||||
|
use DesignPatterns\DataMapper\User;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* UserMapperTest tests the datamappe pattern
|
||||||
|
*/
|
||||||
|
class UserMapperTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $mapper;
|
||||||
|
protected $dbal;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->dbal = $this->getMockBuilder('DesignPatterns\DataMapper\DBAL')
|
||||||
|
->disableAutoload()
|
||||||
|
->setMethods(array('insert', 'update', 'find', 'findAll'))
|
||||||
|
->getMock();
|
||||||
|
|
||||||
|
$this->mapper = new UserMapper($this->dbal);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNewUser()
|
||||||
|
{
|
||||||
|
return array(array(new User(null, 'Odysseus', 'Odysseus@ithaca.gr')));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getExistingUser()
|
||||||
|
{
|
||||||
|
return array(array(new User(1, 'Odysseus', 'Odysseus@ithaca.gr')));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getNewUser
|
||||||
|
*/
|
||||||
|
public function testPersistNew(User $user)
|
||||||
|
{
|
||||||
|
$this->dbal->expects($this->once())
|
||||||
|
->method('insert');
|
||||||
|
$this->mapper->save($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider getExistingUser
|
||||||
|
*/
|
||||||
|
public function testPersistExisting(User $user)
|
||||||
|
{
|
||||||
|
$this->dbal->expects($this->once())
|
||||||
|
->method('update');
|
||||||
|
$this->mapper->save($user);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user