Laravel 4 unit test met phpunit
ik moet nu een unit test schrijven in laravel 4 en dit is de 1e keer dat ik dat moet doen.
na een paar dagen stoeien ben ik tot dit gekomen alleen krijg ik nu het idee dat er iets niet goed gaat.
iemand suggesties of tips?
BVD. Ralph
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php use Motherbase\Engine\Pinboard\PinHandler;
class PinHandlerTest extends TestCase
{
private $pinRepositoryMock;
public function tearDown()
{
Mockery::close();
}
public function setUp()
{
parent::setUp();
$this->pinRepositoryMock = Mockery::mock('\Motherbase\Engine\Pinboard\PinRepositoryInterface');
App::instance('\Motherbase\Engine\Pinboard\PinRepositoryInterface', $this->pinRepositoryMock);
$this->pinHandler = new PinHandler($this->pinRepositoryMock);
}
public function testGetPin()
{
$pinMock = Mockery::Mock('\Motherbase\Engine\Pinboard\Pin');
// test variabelen
$profile_id = 1;
$pin_id = 1;
$image_id = 1;
$this->pinRepositoryMock
->shouldReceive('readPin')
->once()
->with( array( 'profile_id' => $profile_id,
'pin_id '=> $pin_id )
->andReturn('test');
$pinMock ->shouldReceive('getAttribute')
->with('created_at','2014-10-10 15:00:00')
->once();
$pinMock ->shouldReceive('setAttribute')
->with('date','10 OCT')
->once();
$pinMock ->shouldReceive('getAttribute')
->with('image_id','1')
->once();
\Image ::shouldReceive('getUrlById')
->once()
->andReturn('/');
$pinMock ->shouldReceive('setAttribute')
->with('image','/')
->once();
\Profile ::shouldReceive('getMenuProfileById')
->with($profile_id);
->once()
->andReturn(array());
$pin = $this->pinHandler->getPin($profile_id, $pin_id);
$this->assertEquals('test', 'test');
}
}
class PinHandlerTest extends TestCase
{
private $pinRepositoryMock;
public function tearDown()
{
Mockery::close();
}
public function setUp()
{
parent::setUp();
$this->pinRepositoryMock = Mockery::mock('\Motherbase\Engine\Pinboard\PinRepositoryInterface');
App::instance('\Motherbase\Engine\Pinboard\PinRepositoryInterface', $this->pinRepositoryMock);
$this->pinHandler = new PinHandler($this->pinRepositoryMock);
}
public function testGetPin()
{
$pinMock = Mockery::Mock('\Motherbase\Engine\Pinboard\Pin');
// test variabelen
$profile_id = 1;
$pin_id = 1;
$image_id = 1;
$this->pinRepositoryMock
->shouldReceive('readPin')
->once()
->with( array( 'profile_id' => $profile_id,
'pin_id '=> $pin_id )
->andReturn('test');
$pinMock ->shouldReceive('getAttribute')
->with('created_at','2014-10-10 15:00:00')
->once();
$pinMock ->shouldReceive('setAttribute')
->with('date','10 OCT')
->once();
$pinMock ->shouldReceive('getAttribute')
->with('image_id','1')
->once();
\Image ::shouldReceive('getUrlById')
->once()
->andReturn('/');
$pinMock ->shouldReceive('setAttribute')
->with('image','/')
->once();
\Profile ::shouldReceive('getMenuProfileById')
->with($profile_id);
->once()
->andReturn(array());
$pin = $this->pinHandler->getPin($profile_id, $pin_id);
$this->assertEquals('test', 'test');
}
}
Er zijn nog geen reacties op dit bericht.