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
3747365b
Commit
3747365b
authored
Jul 18, 2009
by
piccoloprincipe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] added tests for lazy loading; added error_reporting level; wired association proxy factory
parent
b8090c99
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
38 deletions
+61
-38
ProxyFactory.php
lib/Doctrine/ORM/Proxy/ProxyFactory.php
+1
-12
OneToOneBidirectionalAssociationTest.php
...s/ORM/Functional/OneToOneBidirectionalAssociationTest.php
+28
-12
OneToOneUnidirectionalAssociationTest.php
.../ORM/Functional/OneToOneUnidirectionalAssociationTest.php
+29
-13
TestInit.php
tests/Doctrine/Tests/TestInit.php
+3
-1
No files found.
lib/Doctrine/ORM/Proxy/ProxyFactory.php
View file @
3747365b
...
...
@@ -68,18 +68,7 @@ class ProxyFactory
*/
public
function
getAssociationProxy
(
$owner
,
\Doctrine\ORM\Mapping\AssociationMapping
$assoc
)
{
throw
new
Exception
(
"Not yet implemented."
);
$proxyClassName
=
str_replace
(
'\\'
,
'_'
,
$assoc
->
getTargetEntityName
())
.
'AProxy'
;
if
(
!
class_exists
(
$proxyClassName
,
false
))
{
$this
->
_em
->
getMetadataFactory
()
->
setMetadataFor
(
self
::
$_ns
.
$proxyClassName
,
$this
->
_em
->
getClassMetadata
(
$assoc
->
getTargetEntityName
()));
$fileName
=
$this
->
_cacheDir
.
$proxyClassName
.
'.g.php'
;
if
(
!
file_exists
(
$fileName
))
{
$this
->
_generateAssociationProxyClass
(
$assoc
->
getTargetEntityName
(),
$proxyClassName
,
$fileName
);
}
require
$fileName
;
}
$proxyClassName
=
'\\'
.
self
::
$_ns
.
$proxyClassName
;
$proxyClassName
=
$this
->
_generator
->
generateAssociationProxyClass
(
$assoc
->
getTargetEntityName
());
return
new
$proxyClassName
(
$this
->
_em
,
$assoc
,
$owner
);
}
}
tests/Doctrine/Tests/ORM/Functional/OneToOneBidirectionalAssociationTest.php
View file @
3747365b
...
...
@@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use
Doctrine\Tests\Models\ECommerce\ECommerceCart
;
use
Doctrine\Tests\Models\ECommerce\ECommerceCustomer
;
use
Doctrine\ORM\Mapping\AssociationMapping
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
@@ -54,16 +55,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
public
function
testEagerLoad
()
{
$customer
=
new
ECommerceCustomer
;
$customer
->
setName
(
'Giorgio'
);
$cart
=
new
ECommerceCart
;
$cart
->
setPayment
(
'paypal'
);
$customer
->
setCart
(
$cart
);
$this
->
_em
->
save
(
$customer
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
$this
->
_createFixture
();
$query
=
$this
->
_em
->
createQuery
(
'select c, ca from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c join c.cart ca'
);
$result
=
$query
->
getResultList
();
...
...
@@ -73,10 +65,34 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$this
->
assertEquals
(
'paypal'
,
$customer
->
getCart
()
->
getPayment
());
}
/* TODO: not yet implemented
public
function
testLazyLoad
()
{
$this
->
markTestSkipped
();
$this
->
_createFixture
();
$this
->
_em
->
getConfiguration
()
->
setAllowPartialObjects
(
false
);
$metadata
=
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\Models\ECommerce\ECommerceCustomer'
);
$metadata
->
getAssociationMapping
(
'cart'
)
->
fetchMode
=
AssociationMapping
::
FETCH_LAZY
;
$query
=
$this
->
_em
->
createQuery
(
'select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c'
);
$result
=
$query
->
getResultList
();
$customer
=
$result
[
0
];
}*/
$this
->
assertTrue
(
$customer
->
getCart
()
instanceof
ECommerceCart
);
$this
->
assertEquals
(
'paypal'
,
$customer
->
getCart
()
->
getPayment
());
}
protected
function
_createFixture
()
{
$customer
=
new
ECommerceCustomer
;
$customer
->
setName
(
'Giorgio'
);
$cart
=
new
ECommerceCart
;
$cart
->
setPayment
(
'paypal'
);
$customer
->
setCart
(
$cart
);
$this
->
_em
->
save
(
$customer
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
}
public
function
assertCartForeignKeyIs
(
$value
)
{
$foreignKey
=
$this
->
_em
->
getConnection
()
->
execute
(
'SELECT customer_id FROM ecommerce_carts WHERE id=?'
,
array
(
$this
->
cart
->
getId
()))
->
fetchColumn
();
...
...
tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php
View file @
3747365b
...
...
@@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
use
Doctrine\Tests\Models\ECommerce\ECommerceProduct
;
use
Doctrine\Tests\Models\ECommerce\ECommerceShipping
;
use
Doctrine\ORM\Mapping\AssociationMapping
;
require_once
__DIR__
.
'/../../TestInit.php'
;
...
...
@@ -45,18 +46,9 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$this
->
assertForeignKeyIs
(
null
);
}
public
function
testEagerLoad
()
public
function
_
testEagerLoad
()
{
$product
=
new
ECommerceProduct
;
$product
->
setName
(
'Php manual'
);
$shipping
=
new
ECommerceShipping
;
$shipping
->
setDays
(
'1'
);
$product
->
setShipping
(
$shipping
);
$this
->
_em
->
save
(
$product
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
$this
->
_createFixture
();
$query
=
$this
->
_em
->
createQuery
(
'select p, s from Doctrine\Tests\Models\ECommerce\ECommerceProduct p left join p.shipping s'
);
$result
=
$query
->
getResultList
();
...
...
@@ -66,10 +58,34 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$this
->
assertEquals
(
1
,
$product
->
getShipping
()
->
getDays
());
}
/* TODO: not yet implemented
public
function
testLazyLoad
()
{
$this
->
markTestSkipped
();
$this
->
_createFixture
();
$this
->
_em
->
getConfiguration
()
->
setAllowPartialObjects
(
false
);
$metadata
=
$this
->
_em
->
getClassMetadata
(
'Doctrine\Tests\Models\ECommerce\ECommerceProduct'
);
$metadata
->
getAssociationMapping
(
'shipping'
)
->
fetchMode
=
AssociationMapping
::
FETCH_LAZY
;
$query
=
$this
->
_em
->
createQuery
(
'select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p'
);
$result
=
$query
->
getResultList
();
$product
=
$result
[
0
];
}*/
$this
->
assertTrue
(
$product
->
getShipping
()
instanceof
ECommerceShipping
);
$this
->
assertEquals
(
1
,
$product
->
getShipping
()
->
getDays
());
}
protected
function
_createFixture
()
{
$product
=
new
ECommerceProduct
;
$product
->
setName
(
'Php manual'
);
$shipping
=
new
ECommerceShipping
;
$shipping
->
setDays
(
'1'
);
$product
->
setShipping
(
$shipping
);
$this
->
_em
->
save
(
$product
);
$this
->
_em
->
flush
();
$this
->
_em
->
clear
();
}
public
function
assertForeignKeyIs
(
$value
)
{
$foreignKey
=
$this
->
_em
->
getConnection
()
->
execute
(
'SELECT shipping_id FROM ecommerce_products WHERE id=?'
,
array
(
$this
->
product
->
getId
()))
->
fetchColumn
();
...
...
tests/Doctrine/Tests/TestInit.php
View file @
3747365b
...
...
@@ -4,6 +4,8 @@
*/
namespace
Doctrine\Tests
;
error_reporting
(
E_ALL
|
E_STRICT
);
require_once
'PHPUnit/Framework.php'
;
require_once
'PHPUnit/TextUI/TestRunner.php'
;
require_once
__DIR__
.
'/../../../lib/Doctrine/Common/ClassLoader.php'
;
...
...
@@ -13,4 +15,4 @@ $classLoader = new \Doctrine\Common\ClassLoader();
set_include_path
(
get_include_path
()
.
PATH_SEPARATOR
.
__DIR__
.
DIRECTORY_SEPARATOR
.
'..'
.
DIRECTORY_SEPARATOR
.
'..'
.
DIRECTORY_SEPARATOR
.
'..'
.
DIRECTORY_SEPARATOR
.
'lib'
);
\ 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