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
11cc553e
Commit
11cc553e
authored
Jan 04, 2013
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
! Implementation of feature request #46
parent
9b8bed28
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
136 additions
and
0 deletions
+136
-0
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Registry.php
...nity/EcomDev/PHPUnit/Model/Fixture/Processor/Registry.php
+135
-0
app/code/community/EcomDev/PHPUnit/etc/config.xml
app/code/community/EcomDev/PHPUnit/etc/config.xml
+1
-0
No files found.
app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Registry.php
0 → 100644
View file @
11cc553e
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
/**
* Registry fixture, works great for resetting singletons and other single instances in Magento
*
* Can be used by specifying annotations:
* @singleton catalog/product_type
* @resource catalog/product
* @helper catalog
*
* or by specifying it in Yaml file:
*
* registry:
* singleton:
* - catalog/product_type
* resource:
* - catalog/product
* helper
* - catalog
* - core/url
*
*/
class
EcomDev_PHPUnit_Model_Fixture_Processor_Registry
implements
EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const
STORAGE_KEY
=
'registry'
;
/**
* Clears singletons before tests
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Registry
* @throws RuntimeException
*/
public
function
apply
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$typeToKey
=
array
(
'singleton'
=>
'_singleton/'
,
'resource'
=>
'_resource_singleton/'
,
'helper'
=>
'_helper/'
);
if
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
)
!==
null
)
{
throw
new
RuntimeException
(
'Registry data was not cleared after previous test'
);
}
$oldRegistry
=
array
();
foreach
(
$data
as
$type
=>
$keys
)
{
if
(
!
isset
(
$typeToKey
[
$type
]))
{
continue
;
}
foreach
(
$keys
as
$key
)
{
// Preserve old registry value
$oldRegistry
[
$typeToKey
[
$type
]
.
$key
]
=
Mage
::
registry
(
$typeToKey
[
$type
]
.
$key
);
// Set new value to registry
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
replaceRegistry
(
$typeToKey
[
$type
]
.
$key
,
null
);
}
}
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
$oldRegistry
);
return
$this
;
}
/**
* Sets back old singletons after tests
*
* @param array[] $data
* @param string $key
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
*
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Interface
*/
public
function
discard
(
array
$data
,
$key
,
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
if
(
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
)
===
null
)
{
return
$this
;
}
$oldRegistry
=
$fixture
->
getStorageData
(
self
::
STORAGE_KEY
);
foreach
(
$oldRegistry
as
$key
=>
$value
)
{
// Set old value to registry
EcomDev_PHPUnit_Test_Case_Util
::
app
()
->
replaceRegistry
(
$key
,
$value
);
}
$fixture
->
setStorageData
(
self
::
STORAGE_KEY
,
null
);
return
$this
;
}
/**
* Initializes fixture processor before applying data
*
* @param EcomDev_PHPUnit_Model_Fixture_Interface $fixture
* @return EcomDev_PHPUnit_Model_Fixture_Processor_Registry
*/
public
function
initialize
(
EcomDev_PHPUnit_Model_Fixture_Interface
$fixture
)
{
$options
=
$fixture
->
getOptions
();
$registry
=
array
();
foreach
(
array
(
'singleton'
,
'resource'
,
'helper'
)
as
$type
)
{
if
(
!
isset
(
$options
[
$type
]))
{
continue
;
}
foreach
(
$options
[
$type
]
as
$name
)
{
$registry
[
$type
][]
=
$name
;
}
}
if
(
$registry
)
{
$fixture
->
setFixtureValue
(
'registry'
,
$registry
);
}
return
$this
;
}
}
\ No newline at end of file
app/code/community/EcomDev/PHPUnit/etc/config.xml
View file @
11cc553e
...
@@ -79,6 +79,7 @@
...
@@ -79,6 +79,7 @@
<!-- Default model for loading of fixtures -->
<!-- Default model for loading of fixtures -->
<model>
ecomdev_phpunit/fixture
</model>
<model>
ecomdev_phpunit/fixture
</model>
<processors>
<processors>
<registry>
ecomdev_phpunit/fixture_processor_registry
</registry>
<scope>
ecomdev_phpunit/fixture_processor_scope
</scope>
<scope>
ecomdev_phpunit/fixture_processor_scope
</scope>
<config>
ecomdev_phpunit/fixture_processor_config
</config>
<config>
ecomdev_phpunit/fixture_processor_config
</config>
<config_xml>
ecomdev_phpunit/fixture_processor_config
</config_xml>
<config_xml>
ecomdev_phpunit/fixture_processor_config
</config_xml>
...
...
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