Skip to content

Commit

Permalink
add tests for MockConfig and MockTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
albertborsos committed Jun 21, 2019
1 parent 7b90567 commit ca36f5c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/unit/MockConfigTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

class MockConfigTest extends \Codeception\PHPUnit\TestCase
{
use \albertborsos\ddd\tests\support\base\MockTrait;

public function mockConfigDataProvider()
{
return [
[\albertborsos\ddd\tests\support\base\StubbedForm::class, ['email' => 'a@b.hu'], ['validate' => true]],
];
}

/**
* @dataProvider mockConfigDataProvider
*
* @param $mockedClass
* @param $attributes
* @param $settings
*/
public function testCreateConfig($mockedClass, $attributes, $settings)
{
$mockConfig = \albertborsos\ddd\tests\support\base\MockConfig::create($mockedClass, $attributes, $settings);

$this->assertEquals($mockedClass, $mockConfig['class']);
$this->assertEquals($attributes, $mockConfig['attributes']);
$this->assertEquals($settings, $mockConfig['settings']);
}
}
39 changes: 39 additions & 0 deletions tests/unit/MockTraitTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

class MockTraitTest extends \Codeception\PHPUnit\TestCase
{
use \albertborsos\ddd\tests\support\base\MockTrait;

public function mockObjectDataProvider()
{
return [
'mock form attribute and method' => [\albertborsos\ddd\tests\support\base\StubbedForm::class, ['email' => 'a@b.hu'], ['validate' => true]],
'mock service execute method' => [\albertborsos\ddd\tests\support\base\StubbedService::class, [], ['execute' => true]],
'mock service with multiple settings' => [\albertborsos\ddd\tests\support\base\StubbedService::class, [], [
'execute' => true,
'failedExecute' => false,
]],
];
}

/**
* @dataProvider mockObjectDataProvider
*
* @param $mockedClass
* @param $attributes
* @param $settings
*/
public function testCreateMock($mockedClass, $attributes, $settings)
{
$mockConfig = \albertborsos\ddd\tests\support\base\MockConfig::create($mockedClass, $attributes, $settings);
$mockedObject = $this->mockObject($mockConfig);

foreach ($attributes as $attribute => $expectedValue) {
$this->assertEquals($expectedValue, $mockedObject->$attribute);
}

foreach ($settings as $method => $expectedResult) {
$this->assertEquals($expectedResult, call_user_func([$mockedObject, $method]));
}
}
}

0 comments on commit ca36f5c

Please sign in to comment.