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
4e50792a
Commit
4e50792a
authored
Jul 01, 2009
by
piccoloprincipe
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[2.0] references #2276
parent
455f8774
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
154 additions
and
2 deletions
+154
-2
ECommerceCart.php
tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php
+32
-0
ECommerceCustomer.php
tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php
+43
-0
OneToOneAssociationTest.php
...Doctrine/Tests/ORM/Functional/OneToOneAssociationTest.php
+70
-0
OrmFunctionalTestCase.php
tests/Doctrine/Tests/OrmFunctionalTestCase.php
+9
-2
No files found.
tests/Doctrine/Tests/Models/ECommerce/ECommerceCart.php
0 → 100644
View file @
4e50792a
<?php
namespace
Doctrine\Tests\Models\ECommerce
;
/**
* ECommerceCart
* Represents a typical cart of a shopping application.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_carts")
*/
class
ECommerceCart
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public
$id
;
/**
* @Column(type="string", length=50)
*/
public
$payment
;
/**
* @OneToOne(targetEntity="ECommerceCustomer")
* @JoinColumn(name="customer_id", referencedColumnName="id")
*/
public
$customer
;
}
tests/Doctrine/Tests/Models/ECommerce/ECommerceCustomer.php
0 → 100644
View file @
4e50792a
<?php
namespace
Doctrine\Tests\Models\ECommerce
;
/**
* ECommerceCustomer
* Represents a registered user of a shopping application.
*
* @author Giorgio Sironi
* @Entity
* @Table(name="ecommerce_customers")
*/
class
ECommerceCustomer
{
/**
* @Column(type="integer")
* @Id
* @GeneratedValue(strategy="AUTO")
*/
public
$id
;
/**
* @Column(type="string", length=50)
*/
public
$name
;
/**
* @OneToOne(targetEntity="ECommerceCart", mappedBy="customer", cascade={"save"})
*/
public
$cart
;
public
function
setCart
(
ECommerceCart
$cart
)
{
$this
->
cart
=
$cart
;
$cart
->
customer
=
$this
;
}
public
function
removeCart
()
{
$this
->
cart
->
customer
=
null
;
$this
->
cart
=
null
;
}
}
tests/Doctrine/Tests/ORM/Functional/OneToOneAssociationTest.php
0 → 100644
View file @
4e50792a
<?php
namespace
Doctrine\Tests\ORM\Functional
;
use
Doctrine\Tests\Models\ECommerce\ECommerceCart
;
use
Doctrine\Tests\Models\ECommerce\ECommerceCustomer
;
require_once
__DIR__
.
'/../../TestInit.php'
;
/**
* Tests association mapping for ECommerceCustomer and ECommerceCart.
* The latter is the owning side of the relation.
*/
class
OneToOneAssociationTest
extends
\Doctrine\Tests\OrmFunctionalTestCase
{
public
$customer
;
public
$cart
;
protected
function
setUp
()
{
$this
->
useModelSet
(
'ecommerce'
);
parent
::
setUp
();
$this
->
customer
=
new
ECommerceCustomer
();
$this
->
customer
->
name
=
'John Doe'
;
$this
->
cart
=
new
ECommerceCart
();
$this
->
cart
->
payment
=
'Credit card'
;
}
public
function
testSavesAOneToOneAssociationWithCascadeSaveSet
()
{
$this
->
customer
->
setCart
(
$this
->
cart
);
$this
->
_em
->
save
(
$this
->
customer
);
$this
->
assertCartForeignKeyIs
(
$this
->
customer
->
id
);
}
public
function
testDoesNotSaveAnInverseSideSet
()
{
$this
->
customer
->
cart
=
$this
->
cart
;
$this
->
_em
->
save
(
$this
->
customer
);
$this
->
assertCartForeignKeyIs
(
null
);
}
public
function
testRemovesOneToOneAssociation
()
{
$this
->
customer
->
setCart
(
$this
->
cart
);
$this
->
_em
->
save
(
$this
->
customer
);
$this
->
customer
->
removeCart
();
$this
->
_em
->
flush
();
$this
->
assertCartForeignKeyIs
(
null
);
}
public
function
testLoadsAnAssociation
()
{
$conn
=
$this
->
_em
->
getConnection
();
$conn
->
execute
(
'INSERT INTO ecommerce_customers (name) VALUES ("Giorgio")'
);
$customerId
=
$conn
->
lastInsertId
();
$conn
->
execute
(
"INSERT INTO ecommerce_carts (customer_id, payment) VALUES ('
$customerId
', 'paypal')"
);
$customer
=
$this
->
_em
->
find
(
"Doctrine\Tests\Models\ECommerce\ECommerceCustomer"
,
$customerId
);
$this
->
assertEquals
(
'paypal'
,
$customer
->
cart
->
payment
);
}
public
function
assertCartForeignKeyIs
(
$value
)
{
$foreignKey
=
$this
->
_em
->
getConnection
()
->
execute
(
'SELECT customer_id FROM ecommerce_carts WHERE id=?'
,
array
(
$this
->
cart
->
id
))
->
fetchColumn
();
$this
->
assertEquals
(
$value
,
$foreignKey
);
}
}
tests/Doctrine/Tests/OrmFunctionalTestCase.php
View file @
4e50792a
...
...
@@ -44,7 +44,10 @@ class OrmFunctionalTestCase extends OrmTestCase
'Doctrine\Tests\Models\Company\CompanyEmployee'
,
'Doctrine\Tests\Models\Company\CompanyManager'
),
'ecommerce'
=>
array
(),
'ecommerce'
=>
array
(
'Doctrine\Tests\Models\ECommerce\ECommerceCart'
,
'Doctrine\Tests\Models\ECommerce\ECommerceCustomer'
),
'generic'
=>
array
(
'Doctrine\Tests\Models\Generic\DateTimeModel'
)
...
...
@@ -69,6 +72,10 @@ class OrmFunctionalTestCase extends OrmTestCase
$conn
->
exec
(
'DELETE FROM cms_articles'
);
$conn
->
exec
(
'DELETE FROM cms_users'
);
}
if
(
isset
(
$this
->
_usedModelSets
[
'ecommerce'
]))
{
$conn
->
exec
(
'DELETE FROM ecommerce_carts'
);
$conn
->
exec
(
'DELETE FROM ecommerce_customers'
);
}
if
(
isset
(
$this
->
_usedModelSets
[
'company'
]))
{
$conn
->
exec
(
'DELETE FROM company_persons_friends'
);
$conn
->
exec
(
'DELETE FROM company_managers'
);
...
...
@@ -142,4 +149,4 @@ class OrmFunctionalTestCase extends OrmTestCase
return
\Doctrine\ORM\EntityManager
::
create
(
$conn
,
$config
,
$eventManager
);
}
}
\ 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