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
110f6214
Commit
110f6214
authored
Feb 02, 2013
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
! Added main helper factory
parent
87b5ac9c
Changes
3
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
514 additions
and
0 deletions
+514
-0
app/code/community/EcomDev/PHPUnit/Test/Listener.php
app/code/community/EcomDev/PHPUnit/Test/Listener.php
+3
-0
app/code/community/EcomDev/PHPUnitTest/Test/Lib/Helper.php
app/code/community/EcomDev/PHPUnitTest/Test/Lib/Helper.php
+343
-0
lib/EcomDev/PHPUnit/Helper.php
lib/EcomDev/PHPUnit/Helper.php
+168
-0
No files found.
app/code/community/EcomDev/PHPUnit/Test/Listener.php
View file @
110f6214
...
@@ -59,6 +59,8 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
...
@@ -59,6 +59,8 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
$this
->
getAppReflection
()
->
getMethod
(
'applyTestScope'
)
->
invoke
(
null
);
$this
->
getAppReflection
()
->
getMethod
(
'applyTestScope'
)
->
invoke
(
null
);
}
}
$this
->
firstLevelTestSuite
=
$suite
;
$this
->
firstLevelTestSuite
=
$suite
;
Mage
::
dispatchEvent
(
'phpunit_suite_start_after'
,
array
(
Mage
::
dispatchEvent
(
'phpunit_suite_start_after'
,
array
(
'suite'
=>
$suite
,
'suite'
=>
$suite
,
...
@@ -139,6 +141,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
...
@@ -139,6 +141,7 @@ class EcomDev_PHPUnit_Test_Listener implements PHPUnit_Framework_TestListener
'listener'
=>
$this
'listener'
=>
$this
));
));
if
(
$test
instanceof
PHPUnit_Framework_TestCase
)
{
if
(
$test
instanceof
PHPUnit_Framework_TestCase
)
{
EcomDev_PHPUnit_Helper
::
setTestCase
(
$test
);
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
get_class
(
$test
))
EcomDev_PHPUnit_Test_Case_Util
::
getFixture
(
get_class
(
$test
))
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
setScope
(
EcomDev_PHPUnit_Model_Fixture_Interface
::
SCOPE_LOCAL
)
->
loadByTestCase
(
$test
);
->
loadByTestCase
(
$test
);
...
...
app/code/community/EcomDev/PHPUnitTest/Test/Lib/Helper.php
0 → 100644
View file @
110f6214
This diff is collapsed.
Click to expand it.
lib/EcomDev/PHPUnit/Helper.php
0 → 100644
View file @
110f6214
<?php
/**
* Test Helpers Factory
*
*/
class
EcomDev_PHPUnit_Helper
{
/**
* Helpers container
*
* @var EcomDev_PHPunit_Helper_Interface[]
*/
protected
static
$helpers
=
array
();
/**
* Adds a new helper instance to helpers registry
*
* If $position is specified, it will use value
* from before or after key as related helper
*
* @param EcomDev_PHPunit_Helper_Interface $helper
* @param bool|array $position
*
* @throws RuntimeException
*/
public
static
function
add
(
EcomDev_PHPunit_Helper_Interface
$helper
,
$position
=
false
)
{
if
(
$position
===
false
)
{
self
::
$helpers
[]
=
$helper
;
}
elseif
(
isset
(
$position
[
'after'
])
||
isset
(
$position
[
'before'
]))
{
$isBefore
=
isset
(
$position
[
'before'
]);
$relatedHelper
=
$isBefore
?
$position
[
'before'
]
:
$position
[
'after'
];
if
(
is_string
(
$relatedHelper
))
{
// Retrieving of helper by class name
$relatedHelper
=
current
(
self
::
getHelpersByClass
(
$relatedHelper
));
}
$helperPosition
=
array_search
(
$relatedHelper
,
self
::
$helpers
,
true
);
if
(
$helperPosition
!==
false
)
{
array_splice
(
self
::
$helpers
,
$helperPosition
+
(
$isBefore
?
0
:
1
),
null
,
array
(
$helper
)
);
}
}
else
{
throw
new
RuntimeException
(
'Unknown position specified for helper addition'
);
}
}
/**
* Removes helper by instance
*
* @param EcomDev_PHPUnit_Helper_Interface $helper
*/
public
static
function
remove
(
EcomDev_PHPUnit_Helper_Interface
$helper
)
{
$helperPosition
=
array_search
(
$helper
,
self
::
$helpers
,
true
);
if
(
$helperPosition
!==
false
)
{
array_splice
(
self
::
$helpers
,
$helperPosition
,
1
);
}
}
/**
* Removes all helpers by class name from helpers array
*
* @param string $helperClass
*/
public
static
function
removeByClass
(
$helperClass
)
{
$helpersByClass
=
self
::
getHelpersByClass
(
$helperClass
);
foreach
(
$helpersByClass
as
$helper
)
{
self
::
remove
(
$helper
);
}
}
/**
* Returns helper by action,
* if helper for action was not found it returns false
*
* @param $action
* @return bool|EcomDev_PHPunit_Helper_Interface
*/
public
static
function
getByAction
(
$action
)
{
foreach
(
self
::
$helpers
as
$helper
)
{
if
(
$helper
->
has
(
$action
))
{
return
$helper
;
}
}
return
false
;
}
/**
* Checks existence of a helper for an action
*
* @param string $action
* @return bool
*/
public
static
function
has
(
$action
)
{
return
self
::
getByAction
(
$action
)
!==
false
;
}
/**
* Invokes a helper action with arguments as an array
*
* @param string $action
* @param array $args
*
* @throws RuntimeException
* @return mixed
*/
public
static
function
invokeArgs
(
$action
,
array
$args
)
{
$helper
=
self
::
getByAction
(
$action
);
if
(
!
$helper
)
{
throw
new
RuntimeException
(
sprintf
(
'Cannot find a helper for action "%s"'
,
$action
));
}
return
$helper
->
invoke
(
$action
,
$args
);
}
/**
* Invokes helper action with flat arguments
*
* @param string $action
* @return mixed
*/
public
static
function
invoke
(
$action
/*, $arg1, $arg2, $arg3 ... $argN */
)
{
$args
=
func_get_args
();
array_shift
(
$args
);
return
self
::
invokeArgs
(
$action
,
$args
);
}
/**
* Sets test case to each helper instance
*
* @param PHPUnit_Framework_TestCase $testCase
*/
public
static
function
setTestCase
(
PHPUnit_Framework_TestCase
$testCase
)
{
foreach
(
self
::
$helpers
as
$helper
)
{
$helper
->
setTestCase
(
$testCase
);
}
}
/**
* Finds a helper instance by class name
*
* @param string $className
* @return array
*/
protected
static
function
getHelpersByClass
(
$className
)
{
return
array_filter
(
self
::
$helpers
,
function
(
$item
)
use
(
$className
)
{
return
get_class
(
$item
)
===
$className
;
});
}
}
\ No newline at end of file
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