forked from yiisoft/yii2
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enh Dependency getHasChanged (yiisoft#12928)
* - rename getHasChanged() to isChanged() - updated docs - added tests for Dependency - added useful helpers for inaccessible properties to TestCase
- Loading branch information
1 parent
5f8ec36
commit b641c1f
Showing
8 changed files
with
143 additions
and
18 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
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
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,20 @@ | ||
<?php | ||
|
||
namespace yiiunit\data\cache; | ||
|
||
use yii\caching\Dependency; | ||
|
||
/** | ||
* Class MockDependency | ||
* @package tests\data\cache | ||
* | ||
* @author Boudewijn Vahrmeijer <[email protected]> | ||
* @since 2.0.11 | ||
*/ | ||
class MockDependency extends Dependency | ||
{ | ||
protected function generateDependencyData($cache) | ||
{ | ||
return $this->data; | ||
} | ||
} |
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,52 @@ | ||
<?php | ||
namespace yiiunit\framework\caching; | ||
|
||
|
||
use yii\caching\Cache; | ||
use yii\caching\Dependency; | ||
use yiiunit\data\cache\MockDependency; | ||
use yiiunit\TestCase; | ||
|
||
/** | ||
* Dependency (abstract) tests | ||
* @group caching | ||
* @author Boudewijn Vahrmeijer <[email protected]> | ||
* @since 2.0.11 | ||
*/ | ||
class DependencyTest extends TestCase | ||
{ | ||
public function testResetReusableData() | ||
{ | ||
$value = ['dummy']; | ||
$dependency = new MockDependency(); | ||
$this->setInaccessibleProperty($dependency, '_reusableData', $value, false); | ||
$this->assertEquals($value, $this->getInaccessibleProperty($dependency, '_reusableData')); | ||
|
||
$dependency->resetReusableData(); | ||
|
||
$this->assertEquals([], $this->getInaccessibleProperty($dependency, '_reusableData')); | ||
} | ||
|
||
public function testGenerateReusableHash() | ||
{ | ||
$dependency = $this->getMockForAbstractClass(Dependency::className()); | ||
$dependency->data = 'dummy'; | ||
|
||
$result = $this->invokeMethod($dependency, 'generateReusableHash'); | ||
$this->assertEquals(5, strlen($dependency->data)); | ||
$this->assertEquals(40, strlen($result)); | ||
} | ||
|
||
public function testisChanged() | ||
{ | ||
$dependency = $this->getMockForAbstractClass(Dependency::className()); | ||
$cache = $this->getMockForAbstractClass(Cache::className()); | ||
|
||
$result = $dependency->isChanged($cache); | ||
$this->assertFalse($result); | ||
|
||
$dependency->data = 'changed'; | ||
$result = $dependency->isChanged($cache); | ||
$this->assertTrue($result); | ||
} | ||
} |