-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add tests for MockConfig and MockTrait
- Loading branch information
1 parent
7b90567
commit ca36f5c
Showing
2 changed files
with
68 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])); | ||
} | ||
} | ||
} |