Skip to content

Commit 0803e50

Browse files
committed
Fixed tests
1 parent 955f59d commit 0803e50

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed

tests/Models/ModelEventTest.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ protected function setUp()
3030
Container::unsetEventDispatcher();
3131
}
3232

33-
public function test_save_fires_events()
33+
public function test_save_fires_saving_and_create_events()
3434
{
3535
$dispatcher = m::mock(DispatcherInterface::class)->makePartial();
3636
$dispatcher->shouldReceive('fire')->once()->withArgs([Saving::class]);
37+
$dispatcher->shouldReceive('fire')->once()->withArgs([Creating::class]);
3738
$dispatcher->shouldReceive('fire')->once()->withArgs([Saved::class]);
39+
$dispatcher->shouldReceive('fire')->once()->withArgs([Created::class]);
3840
Container::setEventDispatcher($dispatcher);
3941

4042
$model = new ModelEventSaveStub();
@@ -44,7 +46,9 @@ public function test_save_fires_events()
4446
public function test_create_fires_events()
4547
{
4648
$dispatcher = m::mock(DispatcherInterface::class);
49+
$dispatcher->shouldReceive('fire')->once()->withArgs([Saving::class]);
4750
$dispatcher->shouldReceive('fire')->once()->withArgs([Creating::class]);
51+
$dispatcher->shouldReceive('fire')->once()->withArgs([Saved::class]);
4852
$dispatcher->shouldReceive('fire')->once()->withArgs([Created::class]);
4953
Container::setEventDispatcher($dispatcher);
5054

@@ -60,13 +64,15 @@ public function test_create_fires_events()
6064
$model->setDn('cn=foo,dc=bar,dc=baz');
6165
$model->cn = 'foo';
6266
$model->objectclass = 'bar';
63-
$this->assertTrue($model->create());
67+
$this->assertTrue($model->save());
6468
}
6569

6670
public function test_updating_model_fires_events()
6771
{
6872
$dispatcher = m::mock(DispatcherInterface::class);
73+
$dispatcher->shouldReceive('fire')->once()->withArgs([Saving::class]);
6974
$dispatcher->shouldReceive('fire')->once()->withArgs([Updating::class]);
75+
$dispatcher->shouldReceive('fire')->once()->withArgs([Saved::class]);
7076
$dispatcher->shouldReceive('fire')->once()->withArgs([Updated::class]);
7177
Container::setEventDispatcher($dispatcher);
7278

@@ -108,8 +114,26 @@ public function test_deleting_model_fires_events()
108114

109115
class ModelEventSaveStub extends Model
110116
{
111-
public function create(array $attributes = [])
117+
public function newQueryWithoutScopes()
118+
{
119+
return (new ModelQueryBuilderSaveStub(new Connection()))->setModel($this);
120+
}
121+
122+
public function synchronize()
112123
{
113124
return true;
114125
}
115126
}
127+
128+
class ModelQueryBuilderSaveStub extends Builder
129+
{
130+
public function insert($dn, array $attributes)
131+
{
132+
return true;
133+
}
134+
135+
public function update($dn, array $modifications)
136+
{
137+
return true;
138+
}
139+
}

tests/Models/ModelQueryTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ public function test_create()
109109

110110
$model->setDn('cn=foo,dc=bar,dc=baz');
111111
$model->fill(['cn' => 'foo', 'objectclass' => 'bar']);
112-
$this->assertTrue($model->create());
112+
$this->assertTrue($model->save());
113113
}
114114

115115
public function test_create_without_connection()
@@ -168,8 +168,9 @@ public function test_update()
168168

169169
public function test_update_without_existing_model()
170170
{
171+
Container::addConnection(new Connection());
171172
$this->expectException(ModelDoesNotExistException::class);
172-
$model = new Entry();
173+
$model = new Entry(['objectclass' => 'foo', 'bar', 'cn' => 'baz']);
173174
$model->update();
174175
}
175176

tests/Models/ModelTest.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,12 @@ public function test_is_ancestor_of()
420420
$this->assertTrue($model->isAncestorOf($child));
421421
}
422422

423+
public function test_create_fills_attributes()
424+
{
425+
$model = ModelCreateTestStub::create(['foo' => ['bar']]);
426+
$this->assertEquals(['foo' => ['bar']], $model->getAttributes());
427+
}
428+
423429
public function test_rename()
424430
{
425431
$model = new ModelRenameTestStub();
@@ -457,6 +463,14 @@ public function test_move()
457463
}
458464
}
459465

466+
class ModelCreateTestStub extends Model
467+
{
468+
public function save(array $attributes = [])
469+
{
470+
return true;
471+
}
472+
}
473+
460474
class ModelBootingTestStub extends Model
461475
{
462476
public static function isBooted()

0 commit comments

Comments
 (0)