Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
66fb71ac
Commit
66fb71ac
authored
Apr 12, 2008
by
romanb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Started playing with isolated hydration tests.
parent
234253ed
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
176 additions
and
2 deletions
+176
-2
AllTests.php
tests/Orm/AllTests.php
+4
-0
AllTests.php
tests/Orm/Component/AllTests.php
+2
-2
AllTests.php
tests/Orm/Hydration/AllTests.php
+30
-0
BasicHydrationTest.php
tests/Orm/Hydration/BasicHydrationTest.php
+78
-0
Doctrine_HydratorMockStatement.php
tests/lib/mocks/Doctrine_HydratorMockStatement.php
+62
-0
No files found.
tests/Orm/AllTests.php
View file @
66fb71ac
...
...
@@ -7,7 +7,10 @@ require_once 'lib/DoctrineTestInit.php';
// Suites
require_once
'Orm/Component/AllTests.php'
;
require_once
'Orm/Hydration/AllTests.php'
;
require_once
'Orm/Ticket/AllTests.php'
;
// Tests
require_once
'Orm/UnitOfWorkTestCase.php'
;
class
Orm_AllTests
...
...
@@ -25,6 +28,7 @@ class Orm_AllTests
//$suite->addTestSuite('Orm_ConfigurableTestCase');
$suite
->
addTest
(
Orm_Component_AllTests
::
suite
());
$suite
->
addTest
(
Orm_Hydration_AllTests
::
suite
());
$suite
->
addTest
(
Orm_Ticket_AllTests
::
suite
());
return
$suite
;
...
...
tests/Orm/Component/AllTests.php
View file @
66fb71ac
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'
Dbal
_Component_AllTests::main'
);
define
(
'PHPUnit_MAIN_METHOD'
,
'
Orm
_Component_AllTests::main'
);
}
require_once
'lib/DoctrineTestInit.php'
;
...
...
@@ -29,6 +29,6 @@ class Orm_Component_AllTests
}
}
if
(
PHPUnit_MAIN_METHOD
==
'
Dbal
_Component_AllTests::main'
)
{
if
(
PHPUnit_MAIN_METHOD
==
'
Orm
_Component_AllTests::main'
)
{
Dbal_Component_AllTests
::
main
();
}
tests/Orm/Hydration/AllTests.php
0 → 100644
View file @
66fb71ac
<?php
if
(
!
defined
(
'PHPUnit_MAIN_METHOD'
))
{
define
(
'PHPUnit_MAIN_METHOD'
,
'Orm_Hydration_AllTests::main'
);
}
require_once
'lib/DoctrineTestInit.php'
;
// Tests
require_once
'Orm/Hydration/BasicHydrationTest.php'
;
class
Orm_Hydration_AllTests
{
public
static
function
main
()
{
PHPUnit_TextUI_TestRunner
::
run
(
self
::
suite
());
}
public
static
function
suite
()
{
$suite
=
new
Doctrine_TestSuite
(
'Doctrine Orm Hydration'
);
$suite
->
addTestSuite
(
'Orm_Hydration_BasicHydrationTest'
);
return
$suite
;
}
}
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Hydration_AllTests::main'
)
{
Orm_Hydration_AllTests
::
main
();
}
tests/Orm/Hydration/BasicHydrationTest.php
0 → 100644
View file @
66fb71ac
<?php
require_once
'lib/DoctrineTestInit.php'
;
require_once
'lib/mocks/Doctrine_HydratorMockStatement.php'
;
class
Orm_Hydration_BasicHydrationTest
extends
Doctrine_OrmTestCase
{
protected
function
setUp
()
{
parent
::
setUp
();
}
/**
* Fakes the DQL query: select u.id, u.name from CmsUser u
*
*/
public
function
testBasic
()
{
// Faked query components
$queryComponents
=
array
(
'u'
=>
array
(
'table'
=>
$this
->
sharedFixture
[
'connection'
]
->
getClassMetadata
(
'CmsUser'
),
'mapper'
=>
$this
->
sharedFixture
[
'connection'
]
->
getMapper
(
'CmsUser'
),
'parent'
=>
null
,
'relation'
=>
null
,
'map'
=>
null
)
);
// Faked table alias map
$tableAliasMap
=
array
(
'u'
=>
'u'
);
// Faked result set
$resultSet
=
array
(
//row1
array
(
'u__id'
=>
'1'
,
'u__name'
=>
'romanb'
),
//row2
array
(
'u__id'
=>
'2'
,
'u__name'
=>
'jwage'
)
);
$stmt
=
new
Doctrine_HydratorMockStatement
(
$resultSet
);
$hydrator
=
new
Doctrine_Hydrator
();
$hydrator
->
setQueryComponents
(
$queryComponents
);
$arrayResult
=
$hydrator
->
hydrateResultSet
(
$stmt
,
$tableAliasMap
,
Doctrine
::
HYDRATE_ARRAY
);
$this
->
assertTrue
(
is_array
(
$arrayResult
));
$this
->
assertEquals
(
2
,
count
(
$arrayResult
));
$this
->
assertEquals
(
1
,
$arrayResult
[
0
][
'id'
]);
$this
->
assertEquals
(
'romanb'
,
$arrayResult
[
0
][
'name'
]);
$this
->
assertEquals
(
2
,
$arrayResult
[
1
][
'id'
]);
$this
->
assertEquals
(
'jwage'
,
$arrayResult
[
1
][
'name'
]);
$stmt
->
setResultSet
(
$resultSet
);
$objectResult
=
$hydrator
->
hydrateResultSet
(
$stmt
,
$tableAliasMap
,
Doctrine
::
HYDRATE_RECORD
);
$this
->
assertTrue
(
$objectResult
instanceof
Doctrine_Collection
);
$this
->
assertEquals
(
2
,
count
(
$objectResult
));
$this
->
assertTrue
(
$objectResult
[
0
]
instanceof
Doctrine_Record
);
$this
->
assertEquals
(
1
,
$objectResult
[
0
]
->
id
);
$this
->
assertEquals
(
'romanb'
,
$objectResult
[
0
]
->
name
);
$this
->
assertTrue
(
$objectResult
[
1
]
instanceof
Doctrine_Record
);
$this
->
assertEquals
(
2
,
$objectResult
[
1
]
->
id
);
$this
->
assertEquals
(
'jwage'
,
$objectResult
[
1
]
->
name
);
//Doctrine::dump($res);
$this
->
assertEquals
(
0
,
0
);
}
}
\ No newline at end of file
tests/lib/mocks/Doctrine_HydratorMockStatement.php
0 → 100644
View file @
66fb71ac
<?php
/**
* This class is a mock of the PDOStatement class that can be passed in to the Hydrator
* to test the hydration standalone with faked result sets.
*
* @author Roman Borschel <roman@code-factory.org>
*/
class
Doctrine_HydratorMockStatement
{
private
$_resultSet
;
/**
* Creates a new mock statement that will serve the provided fake result set to clients.
*
* @param array $resultSet The faked SQL result set.
*/
public
function
__construct
(
array
$resultSet
)
{
$this
->
_resultSet
=
$resultSet
;
}
/**
* Fetches all rows from the result set.
*
* NOTE: Must adhere to the PDOStatement::fetchAll() signature that looks as follows:
* array fetchAll ([ int $fetch_style [, int $column_index [, array $ctor_args ]]] )
*
* @return array
*/
public
function
fetchAll
(
$fetchStyle
=
null
,
$columnIndex
=
null
,
array
$ctorArgs
=
null
)
{
return
$this
->
_resultSet
;
}
/**
* Fetches the next row in the result set.
*
* NOTE: Must adhere to the PDOStatement::fetch() signature that looks as follows:
* mixed fetch ([ int $fetch_style [, int $cursor_orientation [, int $cursor_offset ]]] )
*
*/
public
function
fetch
(
$fetchStyle
=
null
,
$cursorOrientation
=
null
,
$cursorOffset
=
null
)
{
return
array_shift
(
$this
->
_resultSet
);
}
/**
* Closes the cursor, enabling the statement to be executed again.
*
* @return boolean
*/
public
function
closeCursor
()
{
return
true
;
}
public
function
setResultSet
(
array
$resultSet
)
{
$this
->
_resultSet
=
$resultSet
;
}
}
\ 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