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
923ba924
Commit
923ba924
authored
Jan 27, 2012
by
Ivan Chepurnyi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
! Added new constraints for table aliases check in config.
parent
0c1c014f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
1 deletion
+154
-1
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
+49
-1
lib/EcomDev/PHPUnit/Constraint/Config/TableAlias.php
lib/EcomDev/PHPUnit/Constraint/Config/TableAlias.php
+105
-0
No files found.
app/code/community/EcomDev/PHPUnit/Test/Case/Config.php
View file @
923ba924
...
...
@@ -82,7 +82,7 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
/**
* A new constraint for checking
module node
* A new constraint for checking
class alias nodes
*
* @param string $group
* @param string $classAlias
...
...
@@ -98,6 +98,22 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
);
}
/**
* A new constraint for checking table alias nodes
*
* @param string $tableAlias
* @param string $expectedTableName
* @param string $type
* @return EcomDev_PHPUnit_Constraint_Config
*/
public
static
function
configTableAlias
(
$tableAlias
,
$expectedTableName
,
$type
=
EcomDev_PHPUnit_Constraint_Config_TableAlias
::
TYPE_TABLE_ALIAS
)
{
return
self
::
config
(
new
EcomDev_PHPUnit_Constraint_Config_TableAlias
(
$tableAlias
,
$expectedTableName
,
$type
)
);
}
/**
* Creates layout constraint
*
...
...
@@ -888,6 +904,38 @@ abstract class EcomDev_PHPUnit_Test_Case_Config extends EcomDev_PHPUnit_Test_Cas
);
}
/**
* Assert that table alias is mapped to expected table name
*
* @param string $tableAlias
* @param string $expectedTableName
* @param string $message
*/
public
static
function
assertTableAlias
(
$tableAlias
,
$expectedTableName
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
configTableAlias
(
$tableAlias
,
$expectedTableName
),
$message
);
}
/**
* Assert that table alias is NOT mapped to expected table name
*
* @param string $tableAlias
* @param string $expectedTableName
* @param string $message
*/
public
static
function
assertTableAliasNot
(
$tableAlias
,
$expectedTableName
,
$message
=
''
)
{
self
::
assertThatConfig
(
self
::
logicalNot
(
self
::
configTableAlias
(
$tableAlias
,
$expectedTableName
)
),
$message
);
}
/**
* Assert that helper alias is mapped to expected class name
*
...
...
lib/EcomDev/PHPUnit/Constraint/Config/TableAlias.php
0 → 100644
View file @
923ba924
<?php
/**
* Table alias constraint
*
*/
class
EcomDev_PHPUnit_Constraint_Config_TableAlias
extends
EcomDev_PHPUnit_Constraint_Config_Abstract
{
const
XML_PATH_MODELS
=
'global/models'
;
const
TYPE_TABLE_ALIAS
=
'table_alias'
;
/**
* Table alias name, e.g. the name of the table within resource
*
* @var string
*/
protected
$_tableAliasName
=
null
;
/**
* Table alias prefix,
* e.g. the prefix for tables of a particular resource model
*
* @var string
*/
protected
$_tableAliasPrefix
=
null
;
/**
* Constraint for evaluation of table alias
*
* @param string $tableAlias
* @param string $expectedTableName
* @param string $type
*/
public
function
__construct
(
$tableAlias
,
$expectedTableName
,
$type
=
self
::
TYPE_TABLE_ALIAS
)
{
if
(
!
strpos
(
$tableAlias
,
'/'
))
{
throw
PHPUnit_Util_InvalidArgumentHelper
::
factory
(
2
,
'table alias'
,
$tableAlias
);
}
list
(
$this
->
_tableAliasPrefix
,
$this
->
_tableAliasName
)
=
explode
(
'/'
,
$tableAlias
,
2
);
$this
->
_expectedValueValidation
+=
array
(
self
::
TYPE_TABLE_ALIAS
=>
array
(
true
,
'is_string'
,
'string'
)
);
$this
->
_typesWithDiff
[]
=
self
::
TYPE_TABLE_ALIAS
;
parent
::
__construct
(
self
::
XML_PATH_MODELS
,
$type
,
$expectedTableName
);
}
/**
* Evaluates table alias is mapped to expected table name
*
* @param Varien_Simplexml_Element $other
* @return boolean
*/
protected
function
evaluateTableAlias
(
$other
)
{
if
(
!
isset
(
$other
->
{
$this
->
_tableAliasPrefix
}))
{
$this
->
setActualValue
(
false
);
return
false
;
}
$modelNode
=
$other
->
{
$this
->
_tableAliasPrefix
};
if
(
!
isset
(
$modelNode
->
entities
)
&&
isset
(
$other
->
{(
string
)
$modelNode
->
resourceModel
}))
{
$modelNode
=
$other
->
{(
string
)
$modelNode
->
resourceModel
};
}
if
(
isset
(
$modelNode
->
entities
->
{
$this
->
_tableAliasName
}
->
table
))
{
$tableName
=
(
string
)
$modelNode
->
entities
->
{
$this
->
_tableAliasName
}
->
table
;
}
else
{
$tableName
=
false
;
}
$this
->
setActualValue
(
$tableName
);
return
$this
->
_actualValue
===
$this
->
_expectedValue
;
}
/**
* Text representation of table alias constaint
*
* @return string
*/
protected
function
textTableAlias
()
{
return
'is mapped to table name'
;
}
/**
* 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 table alias "%s/%s" %s.'
,
$this
->
_tableAliasPrefix
,
$this
->
_tableAliasName
,
$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