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
8ccb7df1
Commit
8ccb7df1
authored
Jul 01, 2009
by
piccoloprincipe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] added new unidirectional one-one association test
parent
b592e44c
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
219 additions
and
2 deletions
+219
-2
ECommerceCart.php
tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php
+9
-0
ECommerceCustomer.php
tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php
+5
-0
ECommerceProduct.php
tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php
+80
-0
ECommerceShipping.php
tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php
+41
-0
AllTests.php
tests/Doctrine/Tests/ORM/Functional/AllTests.php
+2
-1
OneToOneUnidirectionalAssociationTest.php
.../ORM/Functional/OneToOneUnidirectionalAssociationTest.php
+77
-0
OrmFunctionalTestCase.php
tests/Doctrine/Tests/OrmFunctionalTestCase.php
+5
-1
No files found.
tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php
View file @
8ccb7df1
...
...
@@ -29,6 +29,14 @@ class ECommerceCart
* @JoinColumn(name="customer_id", referencedColumnName="id")
*/
private
$customer
;
/**
* @ManyToMany(targetEntity="ECommerceProduct", cascade={"save"})
* @JoinTable(name="ecommerce_carts_products",
joinColumns={{"name"="cart_id", "referencedColumnName"="id"}},
inverseJoinColumns={{"name"="product_id", "referencedColumnName"="id"}})
*/
private
$products
;
public
function
getId
()
{
return
$this
->
id
;
...
...
@@ -62,4 +70,5 @@ class ECommerceCart
public
function
getCustomer
()
{
return
$this
->
customer
;
}
}
tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php
View file @
8ccb7df1
...
...
@@ -41,6 +41,11 @@ class ECommerceCustomer
$this
->
name
=
$name
;
}
/**
* @OneToMany(targetEntity="ECommerceProduct")
public $watched;
*/
public
function
setCart
(
ECommerceCart
$cart
)
{
if
(
$this
->
cart
!==
$cart
)
{
...
...
tests/Doctrine/Tests/Models/ECommerce/ECommerceProduct.php
0 → 100644
View file @
8ccb7df1
<?php
namespace
Doctrine\Tests\Models\ECommerce
;
/**
* ECommerceProduct
* Represents a type of product of a shopping application.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_products")
*/
class
ECommerceProduct
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
private
$id
;
/**
* @Column(type="string", length=50)
*/
private
$name
;
/**
* @ManyToMany(targetEntity="ECommerceCategory", cascade={"save"})
* @JoinTable(name="ecommerce_products_categories",
joinColumns={{"name"="product_id", "referencedColumnName"="id"}},
inverseJoinColumns={{"name"="category_id", "referencedColumnName"="id"}})
private $categories;
*/
/**
* @OneToOne(targetEntity="ECommerceShipping", cascade={"save"})
* @JoinColumn(name="shipping_id", referencedColumnName="id")
*/
private
$shipping
;
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getName
()
{
return
$this
->
name
;
}
public
function
setName
(
$name
)
{
$this
->
name
=
$name
;
}
public
function
getPrice
()
{
return
$this
->
price
;
}
public
function
setPrice
(
$price
)
{
$this
->
price
=
$price
;
}
public
function
getShipping
()
{
return
$this
->
shipping
;
}
public
function
setShipping
(
ECommerceShipping
$shipping
)
{
$this
->
shipping
=
$shipping
;
}
public
function
removeShipping
()
{
$this
->
shipping
=
null
;
}
}
tests/Doctrine/Tests/Models/ECommerce/ECommerceShipping.php
0 → 100644
View file @
8ccb7df1
<?php
namespace
Doctrine\Tests\Models\ECommerce
;
/**
* ECommerceShipping
* Represents a shipping method.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_shippings")
*/
class
ECommerceShipping
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
private
$id
;
/**
* @Column(type="integer")
*/
private
$days
;
public
function
getId
()
{
return
$this
->
id
;
}
public
function
getDays
()
{
return
$this
->
days
;
}
public
function
setDays
(
$days
)
{
$this
->
days
=
$days
;
}
}
tests/Doctrine/Tests/ORM/Functional/AllTests.php
View file @
8ccb7df1
...
...
@@ -26,6 +26,7 @@ class AllTests
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Functional\DetachedEntityTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Functional\QueryCacheTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Functional\QueryTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Functional\OneToOneUnidirectionalAssociationTest'
);
$suite
->
addTestSuite
(
'Doctrine\Tests\ORM\Functional\OneToOneBidirectionalAssociationTest'
);
return
$suite
;
...
...
@@ -34,4 +35,4 @@ class AllTests
if
(
PHPUnit_MAIN_METHOD
==
'Orm_Functional_AllTests::main'
)
{
AllTests
::
main
();
}
\ No newline at end of file
}
tests/Doctrine/Tests/ORM/Functional/OneToOneUnidirectionalAssociationTest.php
0 → 100644
View file @
8ccb7df1
<?php
namespace
Doctrine\Tests\ORM\Functional
;
use
Doctrine\Tests\Models\ECommerce\ECommerceProduct
;
use
Doctrine\Tests\Models\ECommerce\ECommerceShipping
;
require_once
__DIR__
.
'/../../TestInit.php'
;
/**
* Tests a unidirectional one-to-one association mapping (without inheritance).
* Inverse side is not present.
*/
class
OneToOneUnidirectionalAssociationTest
extends
\Doctrine\Tests\OrmFunctionalTestCase
{
private
$product
;
private
$shipping
;
protected
function
setUp
()
{
$this
->
useModelSet
(
'ecommerce'
);
parent
::
setUp
();
$this
->
product
=
new
ECommerceProduct
();
$this
->
product
->
setName
(
'Doctrine 2 Manual'
);
$this
->
shipping
=
new
ECommerceShipping
();
$this
->
shipping
->
setDays
(
'5'
);
}
public
function
testSavesAOneToOneAssociationWithCascadeSaveSet
()
{
$this
->
product
->
setShipping
(
$this
->
shipping
);
$this
->
_em
->
save
(
$this
->
product
);
$this
->
assertForeignKeyIs
(
$this
->
shipping
->
getId
());
}
public
function
testRemovesOneToOneAssociation
()
{
$this
->
product
->
setShipping
(
$this
->
shipping
);
$this
->
_em
->
save
(
$this
->
product
);
$this
->
product
->
removeShipping
();
$this
->
_em
->
flush
();
$this
->
assertForeignKeyIs
(
null
);
}
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
();
$query
=
$this
->
_em
->
createQuery
(
'select p, s from Doctrine\Tests\Models\ECommerce\ECommerceProduct p left join p.shipping s'
);
$result
=
$query
->
getResultList
();
$product
=
$result
[
0
];
$this
->
assertTrue
(
$product
->
getShipping
()
instanceof
ECommerceShipping
);
$this
->
assertEquals
(
1
,
$product
->
getShipping
()
->
getDays
());
}
/* TODO: not yet implemented
public function testLazyLoad() {
}*/
public
function
assertForeignKeyIs
(
$value
)
{
$foreignKey
=
$this
->
_em
->
getConnection
()
->
execute
(
'SELECT shipping_id FROM ecommerce_products WHERE id=?'
,
array
(
$this
->
product
->
getId
()))
->
fetchColumn
();
$this
->
assertEquals
(
$value
,
$foreignKey
);
}
}
tests/Doctrine/Tests/OrmFunctionalTestCase.php
View file @
8ccb7df1
...
...
@@ -46,7 +46,9 @@ class OrmFunctionalTestCase extends OrmTestCase
),
'ecommerce'
=>
array
(
'Doctrine\Tests\Models\ECommerce\ECommerceCart'
,
'Doctrine\Tests\Models\ECommerce\ECommerceCustomer'
'Doctrine\Tests\Models\ECommerce\ECommerceCustomer'
,
'Doctrine\Tests\Models\ECommerce\ECommerceProduct'
,
'Doctrine\Tests\Models\ECommerce\ECommerceShipping'
),
'generic'
=>
array
(
'Doctrine\Tests\Models\Generic\DateTimeModel'
...
...
@@ -75,6 +77,8 @@ class OrmFunctionalTestCase extends OrmTestCase
if
(
isset
(
$this
->
_usedModelSets
[
'ecommerce'
]))
{
$conn
->
exec
(
'DELETE FROM ecommerce_carts'
);
$conn
->
exec
(
'DELETE FROM ecommerce_customers'
);
$conn
->
exec
(
'DELETE FROM ecommerce_products'
);
$conn
->
exec
(
'DELETE FROM ecommerce_shippings'
);
}
if
(
isset
(
$this
->
_usedModelSets
[
'company'
]))
{
$conn
->
exec
(
'DELETE FROM company_persons_friends'
);
...
...
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