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
110a6764
Commit
110a6764
authored
Sep 23, 2006
by
Tanken
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a unit test for access of one-to-one related object from the foreign side. See ticket #108
parent
bcbdba0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
98 additions
and
0 deletions
+98
-0
RelationAccessTestCase.php
tests/RelationAccessTestCase.php
+78
-0
classes.php
tests/classes.php
+17
-0
run.php
tests/run.php
+3
-0
No files found.
tests/RelationAccessTestCase.php
0 → 100644
View file @
110a6764
<?php
class
Doctrine_RelationAccessTestCase
extends
Doctrine_UnitTestCase
{
public
function
prepareData
()
{
$o1
=
new
File_Owner
();
$o1
->
name
=
"owner1"
;
$o2
=
new
File_Owner
();
$o2
->
name
=
"owner2"
;
$f1
=
new
Data_File
();
$f1
->
filename
=
'file1'
;
$f2
=
new
Data_File
();
$f2
->
filename
=
'file2'
;
$f3
=
new
Data_File
();
$f3
->
filename
=
'file3'
;
$o1
->
Data_File
->
filename
=
'file4'
;
$this
->
connection
->
flush
();
$this
->
connection
->
clear
();
}
public
function
prepareTables
()
{
$this
->
tables
=
array
(
"File_Owner"
,
"Data_File"
);
parent
::
prepareTables
();
}
public
function
testAccessOneToOneFromForeignSide
()
{
$check
=
$this
->
connection
->
query
(
"FROM File_Owner WHERE File_Owner.name = 'owner1'"
);
$owner1
=
$this
->
connection
->
query
(
"FROM File_Owner.Data_File WHERE File_Owner.name = 'owner1'"
);
$owner2
=
$this
->
connection
->
query
(
"FROM File_Owner.Data_File WHERE File_Owner.name = 'owner2'"
);
$this
->
assertTrue
(
count
(
$check
)
==
1
);
$this
->
assertTrue
(
count
(
$owner1
)
==
1
);
$this
->
assertTrue
(
count
(
$owner2
)
==
1
);
$check
=
$check
[
0
];
$owner1
=
$owner1
[
0
];
$owner2
=
$owner2
[
0
];
$check2
=
$this
->
connection
->
query
(
"FROM File_Owner WHERE File_Owner.id = "
.
$owner1
->
get
(
'id'
));
$this
->
assertEqual
(
1
,
count
(
$check2
));
$check2
=
$check2
[
0
];
$this
->
assertEqual
(
'owner1'
,
$check2
->
get
(
'name'
));
$this
->
assertTrue
(
isset
(
$owner1
->
Data_File
));
$this
->
assertFalse
(
isset
(
$owner2
->
Data_File
));
$this
->
assertEqual
(
1
,
$check
->
get
(
'id'
));
$this
->
assertEqual
(
1
,
$owner1
->
get
(
'id'
));
$this
->
assertEqual
(
$owner1
->
get
(
'id'
),
$check
->
get
(
'id'
));
$this
->
assertEqual
(
2
,
$owner2
->
get
(
'id'
));
}
public
function
testAccessOneToOneFromLocalSide
()
{
$check
=
$this
->
connection
->
query
(
"FROM Data_File WHERE Data_File.filename = 'file4'"
);
$file1
=
$this
->
connection
->
query
(
"FROM Data_File.File_Owner WHERE Data_File.filename = 'file4'"
);
$file2
=
$this
->
connection
->
query
(
"FROM Data_File.File_Owner WHERE Data_File.filename = 'file1'"
);
$this
->
assertTrue
(
count
(
$check
)
==
1
);
$this
->
assertTrue
(
count
(
$file1
)
==
1
);
$this
->
assertTrue
(
count
(
$file2
)
==
1
);
$check
=
$check
[
0
];
$file1
=
$file1
[
0
];
$file2
=
$file2
[
0
];
$check2
=
$this
->
connection
->
query
(
"FROM Data_File WHERE Data_File.id = "
.
$file1
->
get
(
'id'
));
$this
->
assertEqual
(
1
,
count
(
$check2
));
$check2
=
$check2
[
0
];
$this
->
assertEqual
(
'file4'
,
$check2
->
get
(
'filename'
));
$this
->
assertTrue
(
isset
(
$file1
->
File_Owner
));
$this
->
assertFalse
(
isset
(
$file2
->
File_Owner
));
$this
->
assertEqual
(
4
,
$check
->
get
(
'id'
));
$this
->
assertEqual
(
4
,
$file1
->
get
(
'id'
));
$this
->
assertEqual
(
$file1
->
get
(
'id'
),
$check
->
get
(
'id'
));
$this
->
assertEqual
(
1
,
$file2
->
get
(
'id'
));
}
}
?>
tests/classes.php
View file @
110a6764
...
...
@@ -444,4 +444,21 @@ class BooleanTest extends Doctrine_Record {
$this
->
hasColumn
(
'is_working'
,
'boolean'
);
}
}
class
Data_File
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"filename"
,
"string"
);
$this
->
hasColumn
(
"file_owner_id"
,
"integer"
);
}
public
function
setUp
()
{
$this
->
hasOne
(
"File_Owner"
,
"Data_File.file_owner_id"
);
}
}
class
File_Owner
extends
Doctrine_Record
{
public
function
setTableDefinition
()
{
$this
->
hasColumn
(
"name"
,
"string"
,
255
);
}
public
function
setUp
()
{
$this
->
hasOne
(
"Data_File"
,
"Data_File.file_owner_id"
);
}
}
?>
tests/run.php
View file @
110a6764
...
...
@@ -30,6 +30,7 @@ require_once("SchemaTestCase.php");
require_once
(
"ImportTestCase.php"
);
require_once
(
"BooleanTestCase.php"
);
require_once
(
"EnumTestCase.php"
);
require_once
(
"RelationAccessTestCase.php"
);
error_reporting
(
E_ALL
);
...
...
@@ -88,6 +89,8 @@ $test->addTestCase(new Doctrine_BooleanTestCase());
$test
->
addTestCase
(
new
Doctrine_EnumTestCase
());
$test
->
addTestCase
(
new
Doctrine_RelationAccessTestCase
());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
...
...
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