-
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.
Merge pull request #1 from kingsquare/v1.1
Tests / strictness
- Loading branch information
Showing
10 changed files
with
257 additions
and
29 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
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,22 @@ | ||
language: php | ||
|
||
sudo: false | ||
|
||
php: | ||
- 7.1 | ||
- 7.2 | ||
- 7.3 | ||
|
||
matrix: | ||
fast_finish: true | ||
|
||
cache: | ||
directories: | ||
- $HOME/.composer/cache/files | ||
|
||
install: | ||
- travis_retry composer install --no-interaction --prefer-dist | ||
|
||
script: | ||
- vendor/bin/phpstan.phar analyse -l max --no-interaction --no-progress src/ tests/ | ||
- vendor/bin/phpunit |
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
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 |
---|---|---|
|
@@ -11,6 +11,10 @@ | |
{ | ||
"name": "Misha van Tol", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Robin Speekenbrink", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
|
@@ -23,10 +27,11 @@ | |
}, | ||
"autoload-dev": { | ||
"psr-4": { | ||
"Communibase\\Tests\\": "test/" | ||
"Communibase\\Tests\\": "tests/" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5" | ||
"phpunit/phpunit": "^5", | ||
"phpstan/phpstan-shim": "^0.11.8" | ||
} | ||
} |
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
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
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 |
---|---|---|
|
@@ -17,9 +17,6 @@ final class GetFromDataBagTest extends TestCase | |
*/ | ||
private $dataBag; | ||
|
||
/** | ||
* | ||
*/ | ||
protected function setUp() | ||
{ | ||
$personData = [ | ||
|
@@ -39,20 +36,40 @@ protected function setUp() | |
$this->dataBag->addEntityData('person', $personData); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
protected function tearDown() | ||
{ | ||
unset($this->dataBag); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function invalidPathProvider() | ||
{ | ||
return [ | ||
'empty' => [''], | ||
'non-existant' => ['invalidPath'], | ||
'ends with .' => ['person.'], | ||
'ends with . on subpath' => ['person.firstName.'], | ||
'not a string (int)' => [1], | ||
'not a string (array)' => [[]], | ||
'not a string (null)' => [null], | ||
'not a string (bool)' => [true], | ||
'not a string (float)' => [1.1001], | ||
'not a string (object)' => [new \stdClass], | ||
'starting with .' => ['.person.firstName'], | ||
'has ..' => ['person..firstName'], | ||
'has .. and .' => ['person..firstName.'], | ||
]; | ||
} | ||
|
||
/** | ||
* @dataProvider invalidPathProvider | ||
* @expectedException \Communibase\InvalidDataBagPathException | ||
*/ | ||
public function testInvalidPath() | ||
public function testInvalidPath($path) | ||
{ | ||
$this->dataBag->get('invalidPath'); | ||
$this->dataBag->get($path); | ||
} | ||
|
||
/** | ||
|
@@ -66,6 +83,8 @@ public function provider() | |
['person.emailAddresses.0', ['emailAddress' => '[email protected]', 'type' => 'private']], | ||
['person.emailAddresses.0.emailAddress', '[email protected]'], | ||
['person.emailAddresses.privateGsm.emailAddress', '[email protected]'], | ||
['person.addresses.test', 'default'], | ||
['person.emailAddresses.test', 'default'], | ||
]; | ||
} | ||
|
||
|
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,36 @@ | ||
<?php | ||
|
||
namespace Communibase\Tests; | ||
|
||
use Communibase\DataBag; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class RemoveFromBag | ||
* @author Kingsquare ([email protected]) | ||
* @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl) | ||
*/ | ||
class HasEntityDataTest extends TestCase | ||
{ | ||
public function testHasEntityData() | ||
{ | ||
$personData = [ | ||
'firstName' => 'John', | ||
'emailAddresses' => [ | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'private', | ||
], | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'privateGsm', | ||
] | ||
], | ||
]; | ||
$dataBag = DataBag::create(); | ||
$dataBag->addEntityData('person', $personData); | ||
|
||
$this->assertTrue($dataBag->hasEntityData('person')); | ||
$this->assertFalse($dataBag->hasEntityData('company')); | ||
} | ||
} |
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,117 @@ | ||
<?php | ||
|
||
namespace Communibase\Tests; | ||
|
||
use Communibase\DataBag; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* Class RemoveFromBag | ||
* @author Kingsquare ([email protected]) | ||
* @copyright Copyright (c) Kingsquare BV (http://www.kingsquare.nl) | ||
*/ | ||
class IsDirtyTest extends TestCase | ||
{ | ||
public function testIsDirtyWhenFieldIsChanged() | ||
{ | ||
$personData = [ | ||
'firstName' => 'John', | ||
'emailAddresses' => [ | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'private', | ||
], | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'privateGsm', | ||
] | ||
], | ||
]; | ||
$dataBag = DataBag::create(); | ||
$dataBag->addEntityData('person', $personData); | ||
$dataBag->set('person.firstName', 'Darko'); | ||
$this->assertSame(true, $dataBag->isDirty('person')); | ||
} | ||
|
||
public function testIsDirtyWhenFieldIsUnchanged() | ||
{ | ||
$personData = [ | ||
'firstName' => 'John', | ||
'emailAddresses' => [ | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'private', | ||
], | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'privateGsm', | ||
] | ||
], | ||
]; | ||
$dataBag = DataBag::create(); | ||
$dataBag->addEntityData('person', $personData); | ||
$dataBag->set('person.firstName', 'John'); | ||
$this->assertSame(false, $dataBag->isDirty('person')); | ||
} | ||
|
||
public function testIsDirtyWhenRemovedFromBag() | ||
{ | ||
$personData = [ | ||
'firstName' => 'John', | ||
'emailAddresses' => [ | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'private', | ||
], | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'privateGsm', | ||
] | ||
], | ||
]; | ||
$dataBag = DataBag::create(); | ||
$dataBag->addEntityData('person', $personData); | ||
$dataBag->remove('person.firstName', true); | ||
$this->assertSame(true, $dataBag->isDirty('person')); | ||
} | ||
|
||
public function testIsDirtyWithUnknownPath() | ||
{ | ||
$personData = [ | ||
'firstName' => 'John', | ||
'emailAddresses' => [ | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'private', | ||
], | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'privateGsm', | ||
] | ||
], | ||
]; | ||
$dataBag = DataBag::create(); | ||
$dataBag->addEntityData('person', $personData); | ||
$this->assertNull($dataBag->isDirty('company')); | ||
} | ||
public function testIsDirtyWitNewPath() | ||
{ | ||
$personData = [ | ||
'firstName' => 'John', | ||
'emailAddresses' => [ | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'private', | ||
], | ||
[ | ||
'emailAddress' => '[email protected]', | ||
'type' => 'privateGsm', | ||
] | ||
], | ||
]; | ||
$dataBag = DataBag::create(); | ||
$dataBag->addEntityData('person', $personData); | ||
$dataBag->set('company.title', 'Kingsquare BV'); | ||
$this->assertSame(true, $dataBag->isDirty('company')); | ||
} | ||
} |
Oops, something went wrong.