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
0c1c014f
Commit
0c1c014f
authored
Jan 27, 2012
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
! Added new type of configuration constraint\
# Fixed issue in abstract for default value check
parent
64be18b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
274 additions
and
0 deletions
+274
-0
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
+105
-0
lib/EcomDev/PHPUnit/Constraint/Abstract.php
lib/EcomDev/PHPUnit/Constraint/Abstract.php
+1
-0
lib/EcomDev/PHPUnit/Constraint/Config/Resource.php
lib/EcomDev/PHPUnit/Constraint/Config/Resource.php
+168
-0
No files found.
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
View file @
0c1c014f
...
...
@@ -63,6 +63,23 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
new
EcomDev_PHPUnit_Constraint_Config_Module
(
$moduleName
,
$type
,
$expectedValue
)
);
}
/**
* A new constraint for checking resources node
*
* @param string $moduleName
* @param string $type
* @param string|null $expectedValue
* @return EcomDev_PHPUnit_Constraint_Config
*/
public
static
function
configResource
(
$moduleName
,
$type
=
EcomDev_PHPUnit_Constraint_Config_Resource
::
TYPE_SETUP_DEFINED
,
$expectedValue
=
null
)
{
return
self
::
config
(
new
EcomDev_PHPUnit_Constraint_Config_Resource
(
$moduleName
,
$type
,
self
::
app
()
->
getConfig
()
->
getModuleDir
(
''
,
$moduleName
),
$expectedValue
)
);
}
/**
* A new constraint for checking module node
...
...
@@ -134,6 +151,94 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
self
::
assertThat
(
Mage
::
getConfig
(),
$constraint
,
$message
);
}
/**
* Asserts that config resource for module is defined
*
*
* @param string $moduleName
* @param mixed $expectedResourceName
* @param string $message
*/
public
static
function
assertSetupResourceDefined
(
$moduleName
=
null
,
$expectedResourceName
=
null
,
$message
=
''
)
{
if
(
$moduleName
===
null
)
{
$moduleName
=
self
::
getModuleNameFromCallStack
();
}
self
::
assertThatConfig
(
self
::
configResource
(
$moduleName
,
EcomDev_PHPUnit_Constraint_Config_Resource
::
TYPE_SETUP_DEFINED
,
$expectedResourceName
),
$message
);
}
/**
* Asserts that config resource for module is NOT defined
*
*
* @param string $moduleName
* @param mixed $expectedResourceName
* @param string $message
*/
public
static
function
assertSetupResourceNotDefined
(
$moduleName
=
null
,
$expectedResourceName
=
null
,
$message
=
''
)
{
if
(
$moduleName
===
null
)
{
$moduleName
=
self
::
getModuleNameFromCallStack
();
}
self
::
assertThatConfig
(
self
::
logicalNot
(
self
::
configResource
(
$moduleName
,
EcomDev_PHPUnit_Constraint_Config_Resource
::
TYPE_SETUP_DEFINED
,
$expectedResourceName
)
),
$message
);
}
/**
* Asserts that config resource for module is defined and directory with the same name exists in module
*
*
* @param string $moduleName
* @param mixed $expectedResourceName
* @param string $message
*/
public
static
function
assertSetupResourceExists
(
$moduleName
=
null
,
$expectedResourceName
=
null
,
$message
=
''
)
{
if
(
$moduleName
===
null
)
{
$moduleName
=
self
::
getModuleNameFromCallStack
();
}
self
::
assertThatConfig
(
self
::
configResource
(
$moduleName
,
EcomDev_PHPUnit_Constraint_Config_Resource
::
TYPE_SETUP_EXISTS
,
$expectedResourceName
),
$message
);
}
/**
* Asserts that config resource for module is defined and directory with the same name exists in module
*
*
* @param string $moduleName
* @param mixed $expectedResourceName
* @param string $message
*/
public
static
function
assertSetupResourceNotExists
(
$moduleName
=
null
,
$expectedResourceName
=
null
,
$message
=
''
)
{
if
(
$moduleName
===
null
)
{
$moduleName
=
self
::
getModuleNameFromCallStack
();
}
self
::
assertThatConfig
(
self
::
logicalNot
(
self
::
configResource
(
$moduleName
,
EcomDev_PHPUnit_Constraint_Config_Resource
::
TYPE_SETUP_EXISTS
,
$expectedResourceName
)
),
$message
);
}
/**
* Asserts that config node value is equal to the expected value.
*
...
...
lib/EcomDev/PHPUnit/Constraint/Abstract.php
View file @
0c1c014f
...
...
@@ -109,6 +109,7 @@ abstract class EcomDev_PHPUnit_Constraint_Abstract
// Type check
if
(
isset
(
$this
->
_expectedValueValidation
[
$type
][
1
])
&&
$expectedValue
!==
null
&&
!
$this
->
_expectedValueValidation
[
$type
][
1
](
$expectedValue
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
2
,
$expectedValueType
,
$expectedValue
);
}
...
...
lib/EcomDev/PHPUnit/Constraint/Config/Resource.php
0 → 100644
View file @
0c1c014f
<?php
/**
* Setup resources configuration constraint
*
*/
class
EcomDev_PHPUnit_Constraint_Config_Resource
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
const
XML_PATH_RESOURCES_NODE
=
'global/resources'
;
const
TYPE_SETUP_DEFINED
=
'setup_defined'
;
const
TYPE_SETUP_EXISTS
=
'setup_exists'
;
/**
* Name of the module for constraint
*
* @var string
*/
protected
$_moduleName
=
null
;
/**
* The module directory for constraint
*
* @var string
*/
protected
$_moduleDirectory
=
null
;
/**
* Contraint for evaluation of module config node
*
* @param string $nodePath
* @param string $type
* @param string $moduleDirectory
* @param mixed $expectedValue
*/
public
function
__construct
(
$moduleName
,
$type
,
$moduleDirectory
=
null
,
$expectedValue
=
null
)
{
$this
->
_expectedValueValidation
+=
array
(
self
::
TYPE_SETUP_DEFINED
=>
array
(
false
,
'is_string'
,
'string'
),
self
::
TYPE_SETUP_EXISTS
=>
array
(
false
,
'is_string'
,
'string'
),
);
$this
->
_typesWithDiff
[]
=
self
::
TYPE_SETUP_DEFINED
;
$this
->
_typesWithDiff
[]
=
self
::
TYPE_SETUP_EXISTS
;
parent
::
__construct
(
self
::
XML_PATH_RESOURCES_NODE
,
$type
,
$expectedValue
);
$this
->
_moduleName
=
$moduleName
;
$this
->
_moduleDirectory
=
$moduleDirectory
;
if
(
$this
->
_type
===
self
::
TYPE_SETUP_EXISTS
&&
!
is_dir
(
$moduleDirectory
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
3
,
'real directory'
,
$moduleDirectory
);
}
}
/**
* Returns list of module setup resources
*
* @param Varien_Simplexml_Element $xml
* @return array
*/
protected
function
getModuleSetupResources
(
Varien_Simplexml_Element
$xml
)
{
$resourcesForModule
=
array
();
foreach
(
$xml
->
children
()
as
$resourceNode
)
{
if
(
isset
(
$resourceNode
->
setup
->
module
)
&&
(
string
)
$resourceNode
->
setup
->
module
===
$this
->
_moduleName
)
{
$resourcesForModule
[]
=
$resourceNode
->
getName
();
}
}
return
$resourcesForModule
;
}
/**
* Checks definition of expected resource name
*
* @param Varien_Simplexml_Element $other
*/
protected
function
evaluateSetupDefined
(
$other
)
{
$moduleResources
=
$this
->
getModuleSetupResources
(
$other
);
if
(
$this
->
_expectedValue
===
null
)
{
$this
->
_expectedValue
=
empty
(
$moduleResources
)
?
strtolower
(
$this
->
_moduleName
)
.
'_setup'
:
current
(
$moduleResources
);
}
$this
->
setActualValue
(
$moduleResources
);
return
in_array
(
$this
->
_expectedValue
,
$this
->
_actualValue
);
}
/**
* Represents contraint for definition of setup resources
*
* @return string
*/
public
function
textSetupDefined
()
{
return
sprintf
(
'contains resource definition for %s module with %s name'
,
$this
->
_moduleName
,
$this
->
_expectedValue
);
}
/**
* Checks existanse and definition of expected resource name
*
* @param Varien_Simplexml_Element $other
*/
protected
function
evaluateSetupExists
(
$other
)
{
$moduleResources
=
$this
->
getModuleSetupResources
(
$other
);
if
(
$this
->
_expectedValue
===
null
)
{
$this
->
_expectedValue
=
empty
(
$moduleResources
)
?
strtolower
(
$this
->
_moduleName
)
.
'_setup'
:
current
(
$moduleResources
);
}
if
(
!
is_dir
(
$this
->
_moduleDirectory
.
DIRECTORY_SEPARATOR
.
'sql'
))
{
$this
->
setActualValue
(
array
());
return
false
;
}
$dirIterator
=
new
DirectoryIterator
(
$this
->
_moduleDirectory
.
DIRECTORY_SEPARATOR
.
'sql'
);
$resourceDirectories
=
array
();
foreach
(
$dirIterator
as
$entry
)
{
if
(
$entry
->
isDir
()
&&
!
$entry
->
isDot
())
{
$resourceDirectories
[]
=
$entry
->
getBasename
();
}
}
$this
->
setActualValue
(
$resourceDirectories
);
return
in_array
(
$this
->
_expectedValue
,
$moduleResources
)
&&
in_array
(
$this
->
_expectedValue
,
$this
->
_actualValue
);
}
/**
* Represents contraint for definition of setup resources
*
* @return string
*/
public
function
textSetupExists
()
{
return
sprintf
(
'are defined or created directory for it in sql one of %s module with %s name'
,
$this
->
_moduleName
,
$this
->
_expectedValue
);
}
/**
* Custom failure description for showing config related errors
* (non-PHPdoc)
* @see PHPUnit_Framework_Constraint::customFailureDescription()
*/
protected
function
customFailureDescription
(
$other
,
$description
,
$not
)
{
return
sprintf
(
'Failed asserting that setup resources %s.'
,
$this
->
toString
()
);
}
}
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