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
2a12b679
Commit
2a12b679
authored
Jun 23, 2014
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPUnit 4.0 compatibility
parent
5e093a87
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
52 deletions
+31
-52
app/code/community/EcomDev/PHPUnitTest/Test/Helper/Mock.php
app/code/community/EcomDev/PHPUnitTest/Test/Helper/Mock.php
+4
-4
app/code/community/EcomDev/PHPUnitTest/Test/Lib/Mock/Proxy.php
...ode/community/EcomDev/PHPUnitTest/Test/Lib/Mock/Proxy.php
+0
-16
lib/EcomDev/PHPUnit/Mock/Proxy.php
lib/EcomDev/PHPUnit/Mock/Proxy.php
+27
-32
No files found.
app/code/community/EcomDev/PHPUnitTest/Test/Helper/Mock.php
View file @
2a12b679
...
@@ -26,7 +26,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
...
@@ -26,7 +26,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'model'
,
'catalog/product'
),
'
classNam
e'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'model'
,
'catalog/product'
),
'
typ
e'
,
$mock
);
$this
->
assertAttributeContains
(
'getId'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
'getId'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
array
(
'entity_id'
=>
1
),
'constructorArgs'
,
$mock
);
$this
->
assertAttributeContains
(
array
(
'entity_id'
=>
1
),
'constructorArgs'
,
$mock
);
}
}
...
@@ -39,7 +39,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
...
@@ -39,7 +39,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'model'
,
'catalog/product'
),
'
classNam
e'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'model'
,
'catalog/product'
),
'
typ
e'
,
$mock
);
$this
->
assertAttributeContains
(
'getId'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
'getId'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
array
(
'entity_id'
=>
1
),
'constructorArgs'
,
$mock
);
$this
->
assertAttributeContains
(
array
(
'entity_id'
=>
1
),
'constructorArgs'
,
$mock
);
}
}
...
@@ -52,7 +52,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
...
@@ -52,7 +52,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'block'
,
'catalog/product_view'
),
'
classNam
e'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'block'
,
'catalog/product_view'
),
'
typ
e'
,
$mock
);
$this
->
assertAttributeContains
(
'getTemplate'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
'getTemplate'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
array
(
'product_id'
=>
1
),
'constructorArgs'
,
$mock
);
$this
->
assertAttributeContains
(
array
(
'product_id'
=>
1
),
'constructorArgs'
,
$mock
);
}
}
...
@@ -65,7 +65,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
...
@@ -65,7 +65,7 @@ class EcomDev_PHPUnitTest_Test_Helper_Mock extends EcomDev_PHPUnit_Test_Case
);
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertInstanceOf
(
'EcomDev_PHPUnit_Mock_Proxy'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'block'
,
'catalog/category'
),
'
classNam
e'
,
$mock
);
$this
->
assertAttributeEquals
(
$this
->
getGroupedClassName
(
'block'
,
'catalog/category'
),
'
typ
e'
,
$mock
);
$this
->
assertAttributeContains
(
'getStoreCategories'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
'getStoreCategories'
,
'methods'
,
$mock
);
$this
->
assertAttributeContains
(
'some_value'
,
'constructorArgs'
,
$mock
);
$this
->
assertAttributeContains
(
'some_value'
,
'constructorArgs'
,
$mock
);
}
}
...
...
app/code/community/EcomDev/PHPUnitTest/Test/Lib/Mock/Proxy.php
View file @
2a12b679
...
@@ -102,22 +102,6 @@ class EcomDev_PHPUnitTest_Test_Lib_Mock_Proxy extends PHPUnit_Framework_TestCase
...
@@ -102,22 +102,6 @@ class EcomDev_PHPUnitTest_Test_Lib_Mock_Proxy extends PHPUnit_Framework_TestCase
$this
->
assertAttributeInstanceOf
(
'EcomDev_PHPUnit_AbstractConstraint'
,
'mockInstance'
,
$this
->
mockProxy
);
$this
->
assertAttributeInstanceOf
(
'EcomDev_PHPUnit_AbstractConstraint'
,
'mockInstance'
,
$this
->
mockProxy
);
}
}
public
function
testStaticExpects
()
{
$this
->
setExpectedException
(
'RuntimeException'
,
'staticExpectsProxy'
);
$this
->
mockProxy
->
staticExpects
(
$this
->
any
());
}
public
function
testStaticExpectsProxy
()
{
$this
->
assertAttributeEmpty
(
'mockInstance'
,
$this
->
mockProxy
);
$this
->
assertInstanceOf
(
'PHPUnit_Framework_MockObject_Builder_InvocationMocker'
,
$this
->
mockProxy
->
staticExpectsProxy
(
$this
->
any
())
->
method
(
'compareValues'
)
);
$this
->
assertAttributeInstanceOf
(
'EcomDev_PHPUnit_AbstractConstraint'
,
'mockInstance'
,
$this
->
mockProxy
);
}
public
function
testGetInvocationMocker
()
public
function
testGetInvocationMocker
()
{
{
$this
->
assertAttributeEmpty
(
'mockInstance'
,
$this
->
mockProxy
);
$this
->
assertAttributeEmpty
(
'mockInstance'
,
$this
->
mockProxy
);
...
...
lib/EcomDev/PHPUnit/Mock/Proxy.php
View file @
2a12b679
...
@@ -16,6 +16,8 @@
...
@@ -16,6 +16,8 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
*/
use
EcomDev_Utils_Reflection
as
ReflectionUtil
;
/**
/**
* PHPUnit Mock Object Proxy
* PHPUnit Mock Object Proxy
*
*
...
@@ -35,7 +37,9 @@ class EcomDev_PHPUnit_Mock_Proxy
...
@@ -35,7 +37,9 @@ class EcomDev_PHPUnit_Mock_Proxy
*/
*/
public
function
addMethod
(
$methodName
)
public
function
addMethod
(
$methodName
)
{
{
$this
->
methods
[]
=
$methodName
;
$methods
=
ReflectionUtil
::
getRestrictedPropertyValue
(
$this
,
'methods'
);
$methods
[]
=
$methodName
;
ReflectionUtil
::
setRestrictedPropertyValue
(
$this
,
'methods'
,
$methods
);
return
$this
;
return
$this
;
}
}
...
@@ -48,10 +52,12 @@ class EcomDev_PHPUnit_Mock_Proxy
...
@@ -48,10 +52,12 @@ class EcomDev_PHPUnit_Mock_Proxy
*/
*/
public
function
removeMethod
(
$methodName
)
public
function
removeMethod
(
$methodName
)
{
{
$methodIndex
=
array_search
(
$methodName
,
$this
->
methods
);
$methods
=
ReflectionUtil
::
getRestrictedPropertyValue
(
$this
,
'methods'
);
$methodIndex
=
array_search
(
$methodName
,
$methods
);
if
(
$methodIndex
!==
false
)
{
if
(
$methodIndex
!==
false
)
{
array_splice
(
$
this
->
methods
,
$methodIndex
,
1
);
array_splice
(
$methods
,
$methodIndex
,
1
);
}
}
ReflectionUtil
::
setRestrictedPropertyValue
(
$this
,
'methods'
,
$methods
);
return
$this
;
return
$this
;
}
}
...
@@ -74,7 +80,9 @@ class EcomDev_PHPUnit_Mock_Proxy
...
@@ -74,7 +80,9 @@ class EcomDev_PHPUnit_Mock_Proxy
public
function
getMockInstance
()
public
function
getMockInstance
()
{
{
if
(
$this
->
mockInstance
===
null
)
{
if
(
$this
->
mockInstance
===
null
)
{
$reflection
=
EcomDev_Utils_Reflection
::
getReflection
(
$this
->
className
);
$reflection
=
ReflectionUtil
::
getReflection
(
ReflectionUtil
::
getRestrictedPropertyValue
(
$this
,
'type'
)
);
$this
->
mockInstance
=
(
$reflection
->
isAbstract
()
||
$reflection
->
isInterface
())
$this
->
mockInstance
=
(
$reflection
->
isAbstract
()
||
$reflection
->
isInterface
())
?
$this
->
getMockForAbstractClass
()
:
$this
->
getMock
();
?
$this
->
getMockForAbstractClass
()
:
$this
->
getMock
();
}
}
...
@@ -106,57 +114,43 @@ class EcomDev_PHPUnit_Mock_Proxy
...
@@ -106,57 +114,43 @@ class EcomDev_PHPUnit_Mock_Proxy
}
}
/**
/**
* Registers a new static expectation in the mock object and returns the
* Returns invocation mocker for
* match object which can be infused with further details.
*
*
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* @throws RuntimeException
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
* @return PHPUnit_Framework_MockObject_InvocationMocker
* @throws RuntimeException in case if you call it
*/
*/
public
static
function
staticExpects
(
PHPUnit_Framework_MockObject_Matcher_Invocation
$matcher
)
public
function
__phpunit_getInvocationMocker
(
)
{
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
'This method cannot be called on mock proxy, use staticExpectsProxy instead'
'Mock object proxy cannot be used for retrieving invocation mockers, '
.
'use getMockInstance method for real mock object'
);
);
}
}
/**
/**
* Registers a new static expectation in the mock object and returns the
* Returns static invocation mocker
* match object which can be infused with further details.
*
* @param PHPUnit_Framework_MockObject_Matcher_Invocation $matcher
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
public
function
staticExpectsProxy
(
PHPUnit_Framework_MockObject_Matcher_Invocation
$matcher
)
{
return
$this
->
getMockInstance
()
->
staticExpects
(
$matcher
);
}
/**
* Returns invocation mocker for
*
*
* @throws RuntimeException
* @throws RuntimeException
* @return PHPUnit_Framework_MockObject_InvocationMocker
* @return PHPUnit_Framework_MockObject_InvocationMocker
*/
*/
public
function
__phpunit_get
InvocationMocker
()
public
static
function
__phpunit_getStatic
InvocationMocker
()
{
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
'Mock object proxy cannot be used for retrieving invocation mockers, '
'Mock object proxy cannot be used for retrieving invocation mockers, '
.
'use getMockInstance method for real mock object'
.
'use getMockInstance method for real mock object'
);
);
}
}
/**
/**
* Returns static invocation mocker
* @param $originalObject
*
* @throws RuntimeException
* @return PHPUnit_Framework_MockObject_InvocationMocker
* @return PHPUnit_Framework_MockObject_InvocationMocker
* @since Method available since Release 2.0.0
*/
*/
public
static
function
__phpunit_getStaticInvocationMocker
(
)
public
function
__phpunit_setOriginalObject
(
$originalObject
)
{
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
'Mock object proxy cannot be used for retrieving invocation mockers, '
'Mock object proxy cannot be used for retrieving invocation mockers, '
.
'use getMockInstance method for real mock object'
.
'use getMockInstance method for real mock object'
);
);
}
}
...
@@ -170,7 +164,7 @@ class EcomDev_PHPUnit_Mock_Proxy
...
@@ -170,7 +164,7 @@ class EcomDev_PHPUnit_Mock_Proxy
{
{
throw
new
RuntimeException
(
throw
new
RuntimeException
(
'Mock object proxy cannot be used for verifying mock'
'Mock object proxy cannot be used for verifying mock'
.
'use getMockInstance method for real mock object'
.
'use getMockInstance method for real mock object'
);
);
}
}
...
@@ -189,4 +183,5 @@ class EcomDev_PHPUnit_Mock_Proxy
...
@@ -189,4 +183,5 @@ class EcomDev_PHPUnit_Mock_Proxy
);
);
}
}
}
}
\ 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