Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
EcomDev_PHPUnit
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Open
EcomDev_PHPUnit
Commits
d77b04cd
Commit
d77b04cd
authored
Oct 29, 2011
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+ New feature #12: Support annotations per test function/class to enable/disable cache
parent
1260662b
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
9 deletions
+104
-9
app/code/community/EcomDev/PHPUnit/Model/App.php
app/code/community/EcomDev/PHPUnit/Model/App.php
+33
-9
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
+71
-0
No files found.
app/code/community/EcomDev/PHPUnit/Model/App.php
View file @
d77b04cd
...
@@ -179,15 +179,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
...
@@ -179,15 +179,11 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
// Set using cache
// Set using cache
// for things that shouldn't be reloaded each time
// for things that shouldn't be reloaded each time
EcomDev_Utils_Reflection
::
setRestrictedPropertyValue
(
$this
->
setCacheOptions
(
array
(
$this
->
_cache
,
'_allowedCacheOptions'
,
array
(
'eav'
=>
1
,
'eav'
=>
1
,
'layout'
=>
1
,
'layout'
=>
1
,
'translate'
=>
1
'translate'
=>
1
)
));
);
// Clean cache before the whole suite is running
// Clean cache before the whole suite is running
$this
->
getCache
()
->
clean
();
$this
->
getCache
()
->
clean
();
...
@@ -228,6 +224,34 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
...
@@ -228,6 +224,34 @@ class EcomDev_PHPUnit_Model_App extends Mage_Core_Model_App
return
$this
;
return
$this
;
}
}
/**
* Sets cache options for test case
*
* @param array $options
* @return EcomDev_PHPUnit_Model_App
*/
public
function
setCacheOptions
(
array
$options
)
{
EcomDev_Utils_Reflection
::
setRestrictedPropertyValue
(
$this
->
_cache
,
'_allowedCacheOptions'
,
$options
);
}
/**
* Retrieve cache options for test case
*
* @return array
*/
public
function
getCacheOptions
()
{
return
EcomDev_Utils_Reflection
::
getRestrictedPropertyValue
(
$this
->
_cache
,
'_allowedCacheOptions'
);
}
/**
/**
* Retrieves a model from config and checks it on interface implementation
* Retrieves a model from config and checks it on interface implementation
*
*
...
...
app/code/community/EcomDev/PHPUnit/Model/Fixture.php
View file @
d77b04cd
...
@@ -51,6 +51,9 @@ class EcomDev_PHPUnit_Model_Fixture
...
@@ -51,6 +51,9 @@ class EcomDev_PHPUnit_Model_Fixture
// Key for loaded entities by EAV loaders
// Key for loaded entities by EAV loaders
const
STORAGE_KEY_ENTITIES
=
'entities'
;
const
STORAGE_KEY_ENTITIES
=
'entities'
;
// Key for loaded cache options
const
STORAGE_KEY_CACHE_OPTIONS
=
'cache_options'
;
// Key for created scope models
// Key for created scope models
const
STORAGE_KEY_SCOPE
=
'scope'
;
const
STORAGE_KEY_SCOPE
=
'scope'
;
...
@@ -276,6 +279,11 @@ class EcomDev_PHPUnit_Model_Fixture
...
@@ -276,6 +279,11 @@ class EcomDev_PHPUnit_Model_Fixture
array
(
'class'
,
'method'
)
array
(
'class'
,
'method'
)
);
);
$cacheOptions
=
$testCase
->
getAnnotationByName
(
'cache'
,
'method'
);
$this
->
_parseCacheOptions
(
$cacheOptions
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$testCase
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$testCase
);
return
$this
;
return
$this
;
...
@@ -301,10 +309,43 @@ class EcomDev_PHPUnit_Model_Fixture
...
@@ -301,10 +309,43 @@ class EcomDev_PHPUnit_Model_Fixture
null
,
array
(
$className
,
'loadSharedFixture'
,
'class'
)
null
,
array
(
$className
,
'loadSharedFixture'
,
'class'
)
);
);
$cacheOptions
=
$method
->
invokeArgs
(
null
,
array
(
$className
,
'cache'
,
'class'
)
);
$this
->
_parseCacheOptions
(
$cacheOptions
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$className
);
$this
->
_loadFixtureFiles
(
$fixtures
,
$className
);
return
$this
;
return
$this
;
}
}
/**
* Loads test case cache on off annotations
*
* @param array $annotations
* @return EcomDev_PHPUnit_Model_Fixture
*/
protected
function
_parseCacheOptions
(
$annotations
)
{
$cacheOptions
=
array
();
foreach
(
$annotations
as
$annotation
)
{
list
(
$action
,
$cacheType
)
=
preg_split
(
'/\s+/'
,
trim
(
$annotation
));
$flag
=
(
$action
===
'off'
?
0
:
1
);
if
(
$cacheType
===
'all'
)
{
foreach
(
Mage
::
app
()
->
getCacheInstance
()
->
getTypes
()
as
$type
)
{
$cacheOptions
[
$type
->
getId
()]
=
$flag
;
}
}
else
{
$cacheOptions
[
$cacheType
]
=
$flag
;
}
}
if
(
$cacheOptions
)
{
$this
->
_fixture
[
'cache_options'
]
=
$cacheOptions
;
}
}
/**
/**
* Loads fixture files
* Loads fixture files
*
*
...
@@ -412,6 +453,36 @@ class EcomDev_PHPUnit_Model_Fixture
...
@@ -412,6 +453,36 @@ class EcomDev_PHPUnit_Model_Fixture
$this
->
_fixture
=
array
();
$this
->
_fixture
=
array
();
}
}
/**
* Applies cache options for current test or test case
*
* @param array $options
* @return EcomDev_PHPUnit_Model_Fixture
*/
protected
function
_applyCacheOptions
(
$options
)
{
$originalOptions
=
Mage
::
app
()
->
getCacheOptions
();
$this
->
setStorageData
(
self
::
STORAGE_KEY_CACHE_OPTIONS
,
$originalOptions
);
$options
+=
$originalOptions
;
Mage
::
app
()
->
setCacheOptions
(
$options
);
return
$this
;
}
/**
* Discards changes that were made to Magento cache
*
* @return EcomDev_PHPUnit_Model_Fixture
*/
protected
function
_discardCacheOptions
()
{
Mage
::
app
()
->
setCacheOptions
(
$this
->
getStorageData
(
self
::
STORAGE_KEY_CACHE_OPTIONS
)
);
return
$this
;
}
/**
/**
* Applies fixture configuration values into Mage_Core_Model_Config
* Applies fixture configuration values into Mage_Core_Model_Config
*
*
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment