Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
UserAdminV2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
庄欣
UserAdminV2
Commits
1ed7ec98
Commit
1ed7ec98
authored
Feb 07, 2013
by
Kelt Dockins
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
adding unit tests for ioc changes
parent
b48031b0
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
80 additions
and
0 deletions
+80
-0
laravel/tests/cases/ioc.test.php
+80
-0
No files found.
laravel/tests/cases/ioc.test.php
View file @
1ed7ec98
<?php
/**
* Testing Optional Parameters in classes' Dependency Injection
*/
class
TestOptionalParamClassForIoC
{
public
function
__construct
(
$optional_param
=
42
)
{}
}
/**
* Testing Dependency Injection with this class
*/
class
TestClassOneForIoC
{
public
$_variable
;
}
/**
* Testing Dependency Injection of ClassOne
*/
class
TestClassTwoForIoC
{
public
$class_one
;
public
function
__construct
(
TestClassOneForIoC
$class_one
)
{
$this
->
class_one
=
$class_one
;
}
}
class
IoCTest
extends
PHPUnit_Framework_TestCase
{
/**
...
...
@@ -71,4 +100,54 @@ class IoCTest extends PHPUnit_Framework_TestCase {
$this
->
assertTrue
(
IoC
::
registered
(
'controller: ioc.test'
));
}
/**
* Test that classes with optional parameters can resolve
*/
public
function
testOptionalParamClassResolves
()
{
$test
=
IoC
::
resolve
(
'TestOptionalParamClassForIoC'
);
$this
->
assertInstanceOf
(
'TestOptionalParamClassForIoC'
,
$test
);
}
/**
* Test that we can resolve TestClassOneForIoC using IoC
*/
public
function
testClassOneForIoCResolves
()
{
$test
=
IoC
::
resolve
(
'TestClassOneForIoC'
);
$this
->
assertInstanceOf
(
'TestClassOneForIoC'
,
$test
);
}
/**
* Test that we can resolve TestClassTwoForIoC
*/
public
function
testClassTwoForIoCResolves
()
{
$test
=
IoC
::
resolve
(
'TestClassTwoForIoC'
);
$this
->
assertInstanceOf
(
'TestClassTwoForIoC'
,
$test
);
}
/**
* Test that when we resolve TestClassTwoForIoC we auto resolve
* the dependency for TestClassOneForIoC
*/
public
function
testClassTwoResolvesClassOneDependency
()
{
$test
=
IoC
::
resolve
(
'TestClassTwoForIoC'
);
$this
->
assertInstanceOf
(
'TestClassOneForIoC'
,
$test
->
TestClassOneForIoC
);
}
/**
* Test that when we resolve TestClassTwoForIoC with a parameter
* that it actually uses that instead of a blank class TestClassOneForIoC
*/
public
function
testClassTwoResolvesClassOneWithArgument
()
{
$class_one
=
IoC
::
resolve
(
'TestClassOneForIoC'
);
$class_one
->
test_variable
=
42
;
$class_two
=
IoC
::
resolve
(
'TestClassTwoForIoC'
,
[
$class_one
]);
$this
->
assertEquals
(
42
,
$class_two
->
class_one
->
test_variable
);
}
}
\ 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