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
1133b26c
Commit
1133b26c
authored
Aug 09, 2007
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
1a76029f
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
423 additions
and
122 deletions
+423
-122
LockTestCase.php
tests/Record/LockTestCase.php
+1
-2
StateTestCase.php
tests/Record/StateTestCase.php
+84
-63
RecordTestCase.php
tests/RecordTestCase.php
+64
-57
424BTestCase.php
tests/Ticket/424BTestCase.php
+137
-0
424CTestCase.php
tests/Ticket/424CTestCase.php
+137
-0
No files found.
tests/Record/LockTestCase.php
View file @
1133b26c
<?php
class
Doctrine_Record_Lock_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareTables
()
{
...
...
tests/Record/StateTestCase.php
View file @
1133b26c
...
...
@@ -39,8 +39,28 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase
parent
::
prepareTables
();
}
public
function
prepareData
()
{
}
public
function
prepareData
()
{
}
public
function
testAssigningAutoincId
()
{
$user
=
new
User
();
$this
->
assertEqual
(
$user
->
id
,
null
);
$user
->
name
=
'zYne'
;
$user
->
save
();
$this
->
assertEqual
(
$user
->
id
,
1
);
$user
->
id
=
2
;
$this
->
assertEqual
(
$user
->
id
,
2
);
$user
->
save
();
}
/**
public function testAssignFieldsToProxies()
{
$user = new User();
...
...
@@ -228,4 +248,5 @@ class Doctrine_Record_State_TestCase extends Doctrine_UnitTestCase
$this->assertEqual($user2->password,UPWD2) ;
$this->assertEqual($user2->loginname,null) ;
}
*/
}
tests/RecordTestCase.php
View file @
1133b26c
...
...
@@ -42,6 +42,67 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
parent
::
prepareTables
();
}
public
function
testOne2OneForeign
()
{
$user
=
new
User
();
$user
->
name
=
"Richard Linklater"
;
$rel
=
$user
->
getTable
()
->
getRelation
(
'Account'
);
$this
->
assertTrue
(
$rel
instanceof
Doctrine_Relation_ForeignKey
);
$account
=
$user
->
Account
;
$account
->
amount
=
1000
;
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
state
(),
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertEqual
(
$account
->
entity_id
->
getOid
(),
$user
->
getOid
());
$this
->
assertEqual
(
$account
->
amount
,
1000
);
$this
->
assertEqual
(
$user
->
name
,
"Richard Linklater"
);
$user
->
save
();
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$user
->
refresh
();
$account
=
$user
->
Account
;
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$this
->
assertEqual
(
$account
->
amount
,
1000
);
$this
->
assertEqual
(
$user
->
name
,
"Richard Linklater"
);
$user
=
new
User
();
$user
->
name
=
'John Rambo'
;
$account
=
$user
->
Account
;
$account
->
amount
=
2000
;
$this
->
assertEqual
(
$account
->
getTable
()
->
getColumnNames
(),
array
(
'id'
,
'entity_id'
,
'amount'
));
$this
->
connection
->
flush
();
$this
->
assertEqual
(
$user
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
getTable
()
->
getColumnNames
(),
array
(
'id'
,
'entity_id'
,
'amount'
));
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$this
->
assertEqual
(
$account
->
amount
,
2000
);
$user
=
$user
->
getTable
()
->
find
(
$user
->
id
);
$this
->
assertEqual
(
$user
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$account
=
$user
->
Account
;
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$account
->
getTable
()
->
getColumnNames
(),
array
(
'id'
,
'entity_id'
,
'amount'
));
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$this
->
assertEqual
(
$account
->
amount
,
2000
);
$this
->
assertEqual
(
$user
->
name
,
"John Rambo"
);
}
public
function
testIssetForPrimaryKey
()
{
$this
->
assertTrue
(
isset
(
$this
->
users
[
0
]
->
id
));
...
...
@@ -50,9 +111,9 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
$user
=
new
User
();
$this
->
assert
Fals
e
(
isset
(
$user
->
id
));
$this
->
assert
Fals
e
(
isset
(
$user
[
'id'
]));
$this
->
assert
Fals
e
(
$user
->
contains
(
'id'
));
$this
->
assert
Tru
e
(
isset
(
$user
->
id
));
$this
->
assert
Tru
e
(
isset
(
$user
[
'id'
]));
$this
->
assert
Tru
e
(
$user
->
contains
(
'id'
));
}
public
function
testNotNullConstraint
()
...
...
@@ -312,60 +373,6 @@ class Doctrine_Record_TestCase extends Doctrine_UnitTestCase
}
public
function
testOne2OneForeign
()
{
$user
=
new
User
();
$user
->
name
=
"Richard Linklater"
;
$account
=
$user
->
Account
;
$account
->
amount
=
1000
;
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
state
(),
Doctrine_Record
::
STATE_TDIRTY
);
$this
->
assertEqual
(
$account
->
entity_id
->
getOid
(),
$user
->
getOid
());
$this
->
assertEqual
(
$account
->
amount
,
1000
);
$this
->
assertEqual
(
$user
->
name
,
"Richard Linklater"
);
$user
->
save
();
$user
->
refresh
();
$account
=
$user
->
Account
;
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$this
->
assertEqual
(
$account
->
amount
,
1000
);
$this
->
assertEqual
(
$user
->
name
,
"Richard Linklater"
);
$user
=
new
User
();
$user
->
name
=
"John Rambo"
;
$account
=
$user
->
Account
;
$account
->
amount
=
2000
;
$this
->
assertEqual
(
$account
->
getTable
()
->
getColumnNames
(),
array
(
"id"
,
"entity_id"
,
"amount"
));
$this
->
connection
->
flush
();
$this
->
assertEqual
(
$user
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
getTable
()
->
getColumnNames
(),
array
(
"id"
,
"entity_id"
,
"amount"
));
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$this
->
assertEqual
(
$account
->
amount
,
2000
);
$user
=
$user
->
getTable
()
->
find
(
$user
->
id
);
$this
->
assertEqual
(
$user
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$account
=
$user
->
Account
;
$this
->
assertTrue
(
$account
instanceof
Account
);
$this
->
assertEqual
(
$account
->
state
(),
Doctrine_Record
::
STATE_CLEAN
);
$this
->
assertEqual
(
$account
->
getTable
()
->
getColumnNames
(),
array
(
"id"
,
"entity_id"
,
"amount"
));
$this
->
assertEqual
(
$account
->
entity_id
,
$user
->
id
);
$this
->
assertEqual
(
$account
->
amount
,
2000
);
$this
->
assertEqual
(
$user
->
name
,
"John Rambo"
);
}
public
function
testGet
()
{
...
...
tests/Ticket/424BTestCase.php
0 → 100644
View file @
1133b26c
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Ticket424B_TestCase
*
* This test case tests many-many relationship with non-autoincrement primary key
*
* @package Doctrine
* @author Tamcy <7am.online@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class
Doctrine_Ticket_424B_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
$this
->
tables
=
array
(
'mmrUser_B'
,
'mmrGroup_B'
,
'mmrGroupUser_B'
);
parent
::
prepareTables
();
}
protected
function
newGroup
(
$code
,
$name
)
{
$group
=
new
mmrGroup_B
();
$group
->
id
=
$code
;
$group
->
name
=
$name
;
$group
->
save
();
return
$group
;
}
protected
function
newUser
(
$code
,
$name
,
$groups
)
{
$u
=
new
mmrUser_B
();
$u
->
id
=
$code
;
$u
->
name
=
$name
;
foreach
(
$groups
as
$idx
=>
$group
)
{
$u
->
Group
[
$idx
]
=
$group
;
}
$u
->
save
();
return
$u
;
}
public
function
testManyManyRelationWithAliasColumns
()
{
$groupA
=
$this
->
newGroup
(
1
,
'Group A'
);
$groupB
=
$this
->
newGroup
(
2
,
'Group B'
);
$groupC
=
$this
->
newGroup
(
3
,
'Group C'
);
$john
=
$this
->
newUser
(
1
,
'John'
,
array
(
$groupA
,
$groupB
));
$peter
=
$this
->
newUser
(
2
,
'Peter'
,
array
(
$groupA
,
$groupC
));
$alan
=
$this
->
newUser
(
3
,
'Alan'
,
array
(
$groupB
,
$groupC
));
$q
=
new
Doctrine_Query
();
$gu
=
$q
->
from
(
'mmrGroupUser_B'
)
->
execute
();
$this
->
assertEqual
(
count
(
$gu
),
6
);
// Direct query
$q
=
new
Doctrine_Query
();
$gu
=
$q
->
from
(
'mmrGroupUser_B'
)
->
where
(
'group_id = ?'
,
$groupA
->
id
)
->
execute
();
$this
->
assertEqual
(
count
(
$gu
),
2
);
// Query by join
$q
=
new
Doctrine_Query
();
$userOfGroupAByName
=
$q
->
from
(
'mmrUser_B u, u.Group g'
)
->
where
(
'g.name = ?'
,
array
(
$groupA
->
name
));
$q
->
execute
();
$this
->
assertEqual
(
count
(
$userOfGroupAByName
),
2
);
}
}
class
mmrUser_B
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'mmrGroup_B as Group'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'group_id'
,
'refClass'
=>
'mmrGroupUser_B'
));
}
public
function
setTableDefinition
()
{
// Works when
$this
->
hasColumn
(
'id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
mmrGroup_B
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'mmrUser_B'
,
array
(
'local'
=>
'group_id'
,
'foreign'
=>
'user_id'
,
'refClass'
=>
'mmrGroupUser_B'
));
}
public
function
setTableDefinition
()
{
// Works when
$this
->
hasColumn
(
'id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
mmrGroupUser_B
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'user_id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'group_id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
}
}
tests/Ticket/424CTestCase.php
0 → 100644
View file @
1133b26c
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* Doctrine_Ticket424B_TestCase
*
* This test case tests many-many relationship with non-autoincrement, alias primary key
*
* @package Doctrine
* @author Tamcy <7am.online@gmail.com>
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @category Object Relational Mapping
* @link www.phpdoctrine.com
* @since 1.0
* @version $Revision$
*/
class
Doctrine_Ticket_424C_TestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
}
public
function
prepareTables
()
{
$this
->
tables
=
array
(
'mmrUser_C'
,
'mmrGroup_C'
,
'mmrGroupUser_C'
);
parent
::
prepareTables
();
}
protected
function
newGroup
(
$code
,
$name
)
{
$group
=
new
mmrGroup_C
();
$group
->
id
=
$code
;
$group
->
name
=
$name
;
$group
->
save
();
return
$group
;
}
protected
function
newUser
(
$code
,
$name
,
$groups
)
{
$u
=
new
mmrUser_C
();
$u
->
id
=
$code
;
$u
->
name
=
$name
;
foreach
(
$groups
as
$idx
=>
$group
)
{
$u
->
Group
[
$idx
]
=
$group
;
}
$u
->
save
();
return
$u
;
}
public
function
testManyManyRelationWithAliasColumns
()
{
$groupA
=
$this
->
newGroup
(
1
,
'Group A'
);
$groupB
=
$this
->
newGroup
(
2
,
'Group B'
);
$groupC
=
$this
->
newGroup
(
3
,
'Group C'
);
$john
=
$this
->
newUser
(
1
,
'John'
,
array
(
$groupA
,
$groupB
));
$peter
=
$this
->
newUser
(
2
,
'Peter'
,
array
(
$groupA
,
$groupC
));
$alan
=
$this
->
newUser
(
3
,
'Alan'
,
array
(
$groupB
,
$groupC
));
$q
=
new
Doctrine_Query
();
$gu
=
$q
->
from
(
'mmrGroupUser_C'
)
->
execute
();
$this
->
assertEqual
(
count
(
$gu
),
6
);
// Direct query
$q
=
new
Doctrine_Query
();
$gu
=
$q
->
from
(
'mmrGroupUser_C'
)
->
where
(
'group_id = ?'
,
$groupA
->
id
)
->
execute
();
$this
->
assertEqual
(
count
(
$gu
),
2
);
// Query by join
$q
=
new
Doctrine_Query
();
$userOfGroupAByName
=
$q
->
from
(
'mmrUser_C u, u.Group g'
)
->
where
(
'g.name = ?'
,
array
(
$groupA
->
name
));
$q
->
execute
();
$this
->
assertEqual
(
count
(
$userOfGroupAByName
),
2
);
}
}
class
mmrUser_C
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'mmrGroup_C as Group'
,
array
(
'local'
=>
'user_id'
,
'foreign'
=>
'group_id'
,
'refClass'
=>
'mmrGroupUser_C'
));
}
public
function
setTableDefinition
()
{
// Works when
$this
->
hasColumn
(
'g_id as id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
mmrGroup_C
extends
Doctrine_Record
{
public
function
setUp
()
{
$this
->
hasMany
(
'mmrUser_C'
,
array
(
'local'
=>
'group_id'
,
'foreign'
=>
'user_id'
,
'refClass'
=>
'mmrGroupUser_C'
));
}
public
function
setTableDefinition
()
{
// Works when
$this
->
hasColumn
(
'u_id as id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'name'
,
'string'
,
30
);
}
}
class
mmrGroupUser_C
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
'user_id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
$this
->
hasColumn
(
'group_id'
,
'string'
,
30
,
array
(
'primary'
=>
true
));
}
}
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