Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Sign in
Toggle navigation
S
Silex
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
common
Silex
Commits
fbb5a69d
Commit
fbb5a69d
authored
Mar 29, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use $app in tests, minor CS fixes
parent
a085d9e2
Changes
10
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
127 additions
and
121 deletions
+127
-121
src/Silex/Controller.php
src/Silex/Controller.php
+1
-0
src/Silex/Extension/SessionExtension.php
src/Silex/Extension/SessionExtension.php
+1
-0
src/Silex/Extension/TwigExtension.php
src/Silex/Extension/TwigExtension.php
+1
-0
tests/Silex/Tests/ApplicationTest.php
tests/Silex/Tests/ApplicationTest.php
+18
-17
tests/Silex/Tests/BeforeAfterFilterTest.php
tests/Silex/Tests/BeforeAfterFilterTest.php
+27
-27
tests/Silex/Tests/ControllerCollectionTest.php
tests/Silex/Tests/ControllerCollectionTest.php
+1
-0
tests/Silex/Tests/ControllerTest.php
tests/Silex/Tests/ControllerTest.php
+1
-0
tests/Silex/Tests/ErrorHandlerTest.php
tests/Silex/Tests/ErrorHandlerTest.php
+28
-28
tests/Silex/Tests/FunctionalTest.php
tests/Silex/Tests/FunctionalTest.php
+5
-5
tests/Silex/Tests/RouterTest.php
tests/Silex/Tests/RouterTest.php
+44
-44
No files found.
src/Silex/Controller.php
View file @
fbb5a69d
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
namespace
Silex
;
namespace
Silex
;
use
Silex\Exception\ControllerFrozenException
;
use
Silex\Exception\ControllerFrozenException
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\Routing\Route
;
/**
/**
...
...
src/Silex/Extension/SessionExtension.php
View file @
fbb5a69d
...
@@ -13,6 +13,7 @@ namespace Silex\Extension;
...
@@ -13,6 +13,7 @@ namespace Silex\Extension;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ExtensionInterface
;
use
Silex\ExtensionInterface
;
use
Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage
;
use
Symfony\Component\HttpFoundation\SessionStorage\NativeSessionStorage
;
use
Symfony\Component\HttpFoundation\Session
;
use
Symfony\Component\HttpFoundation\Session
;
use
Symfony\Component\HttpKernel\Events
as
HttpKernelEvents
;
use
Symfony\Component\HttpKernel\Events
as
HttpKernelEvents
;
...
...
src/Silex/Extension/TwigExtension.php
View file @
fbb5a69d
...
@@ -13,6 +13,7 @@ namespace Silex\Extension;
...
@@ -13,6 +13,7 @@ namespace Silex\Extension;
use
Silex\Application
;
use
Silex\Application
;
use
Silex\ExtensionInterface
;
use
Silex\ExtensionInterface
;
use
Symfony\Bridge\Twig\Extension\RoutingExtension
;
use
Symfony\Bridge\Twig\Extension\RoutingExtension
;
use
Symfony\Bridge\Twig\Extension\TranslationExtension
;
use
Symfony\Bridge\Twig\Extension\TranslationExtension
;
...
...
tests/Silex/Tests/ApplicationTest.php
View file @
fbb5a69d
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
namespace
Silex\Tests
;
namespace
Silex\Tests
;
use
Silex\Application
;
use
Silex\Application
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
/**
/**
...
@@ -23,64 +24,64 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
...
@@ -23,64 +24,64 @@ class ApplicationTest extends \PHPUnit_Framework_TestCase
{
{
public
function
testMatchReturnValue
()
public
function
testMatchReturnValue
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$returnValue
=
$app
lication
->
match
(
'/foo'
,
function
()
{});
$returnValue
=
$app
->
match
(
'/foo'
,
function
()
{});
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$returnValue
=
$app
lication
->
get
(
'/foo'
,
function
()
{});
$returnValue
=
$app
->
get
(
'/foo'
,
function
()
{});
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$returnValue
=
$app
lication
->
post
(
'/foo'
,
function
()
{});
$returnValue
=
$app
->
post
(
'/foo'
,
function
()
{});
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$returnValue
=
$app
lication
->
put
(
'/foo'
,
function
()
{});
$returnValue
=
$app
->
put
(
'/foo'
,
function
()
{});
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$returnValue
=
$app
lication
->
delete
(
'/foo'
,
function
()
{});
$returnValue
=
$app
->
delete
(
'/foo'
,
function
()
{});
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
$this
->
assertInstanceOf
(
'Silex\Controller'
,
$returnValue
);
}
}
public
function
testGetRequest
()
public
function
testGetRequest
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
get
(
'/'
,
function
()
{
$app
->
get
(
'/'
,
function
()
{
return
'root'
;
return
'root'
;
});
});
$request
=
Request
::
create
(
'/'
);
$request
=
Request
::
create
(
'/'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
assertEquals
(
$request
,
$app
lication
[
'request'
]);
$this
->
assertEquals
(
$request
,
$app
[
'request'
]);
}
}
public
function
testgetRoutesWithNoRoutes
()
public
function
testgetRoutesWithNoRoutes
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$routes
=
$app
lication
[
'routes'
];
$routes
=
$app
[
'routes'
];
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\RouteCollection'
,
$routes
);
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\RouteCollection'
,
$routes
);
$this
->
assertEquals
(
0
,
count
(
$routes
->
all
()));
$this
->
assertEquals
(
0
,
count
(
$routes
->
all
()));
}
}
public
function
testgetRoutesWithRoutes
()
public
function
testgetRoutesWithRoutes
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
get
(
'/foo'
,
function
()
{
$app
->
get
(
'/foo'
,
function
()
{
return
'foo'
;
return
'foo'
;
});
});
$app
lication
->
get
(
'/bar'
,
function
()
{
$app
->
get
(
'/bar'
,
function
()
{
return
'bar'
;
return
'bar'
;
});
});
$routes
=
$app
lication
[
'routes'
];
$routes
=
$app
[
'routes'
];
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\RouteCollection'
,
$routes
);
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\RouteCollection'
,
$routes
);
$this
->
assertEquals
(
0
,
count
(
$routes
->
all
()));
$this
->
assertEquals
(
0
,
count
(
$routes
->
all
()));
$app
lication
->
flush
();
$app
->
flush
();
$this
->
assertEquals
(
2
,
count
(
$routes
->
all
()));
$this
->
assertEquals
(
2
,
count
(
$routes
->
all
()));
}
}
}
}
tests/Silex/Tests/BeforeAfterFilterTest.php
View file @
fbb5a69d
...
@@ -29,25 +29,25 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
...
@@ -29,25 +29,25 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$i
=
0
;
$i
=
0
;
$test
=
$this
;
$test
=
$this
;
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
before
(
function
()
use
(
&
$i
,
$test
)
{
$app
->
before
(
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
0
,
$i
);
$test
->
assertEquals
(
0
,
$i
);
$i
++
;
$i
++
;
});
});
$app
lication
->
match
(
'/foo'
,
function
()
use
(
&
$i
,
$test
)
{
$app
->
match
(
'/foo'
,
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
1
,
$i
);
$test
->
assertEquals
(
1
,
$i
);
$i
++
;
$i
++
;
});
});
$app
lication
->
after
(
function
()
use
(
&
$i
,
$test
)
{
$app
->
after
(
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
2
,
$i
);
$test
->
assertEquals
(
2
,
$i
);
$i
++
;
$i
++
;
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
assertEquals
(
3
,
$i
);
$this
->
assertEquals
(
3
,
$i
);
}
}
...
@@ -56,19 +56,19 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
...
@@ -56,19 +56,19 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
{
{
$i
=
0
;
$i
=
0
;
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
use
(
&
$i
)
{
$app
->
match
(
'/foo'
,
function
()
use
(
&
$i
)
{
$i
++
;
$i
++
;
return
new
Response
(
'foo'
);
return
new
Response
(
'foo'
);
});
});
$app
lication
->
after
(
function
()
use
(
&
$i
)
{
$app
->
after
(
function
()
use
(
&
$i
)
{
$i
++
;
$i
++
;
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
assertEquals
(
2
,
$i
);
$this
->
assertEquals
(
2
,
$i
);
}
}
...
@@ -78,35 +78,35 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
...
@@ -78,35 +78,35 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
$i
=
0
;
$i
=
0
;
$test
=
$this
;
$test
=
$this
;
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
before
(
function
()
use
(
&
$i
,
$test
)
{
$app
->
before
(
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
0
,
$i
);
$test
->
assertEquals
(
0
,
$i
);
$i
++
;
$i
++
;
});
});
$app
lication
->
before
(
function
()
use
(
&
$i
,
$test
)
{
$app
->
before
(
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
1
,
$i
);
$test
->
assertEquals
(
1
,
$i
);
$i
++
;
$i
++
;
});
});
$app
lication
->
match
(
'/foo'
,
function
()
use
(
&
$i
,
$test
)
{
$app
->
match
(
'/foo'
,
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
2
,
$i
);
$test
->
assertEquals
(
2
,
$i
);
$i
++
;
$i
++
;
});
});
$app
lication
->
after
(
function
()
use
(
&
$i
,
$test
)
{
$app
->
after
(
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
3
,
$i
);
$test
->
assertEquals
(
3
,
$i
);
$i
++
;
$i
++
;
});
});
$app
lication
->
after
(
function
()
use
(
&
$i
,
$test
)
{
$app
->
after
(
function
()
use
(
&
$i
,
$test
)
{
$test
->
assertEquals
(
4
,
$i
);
$test
->
assertEquals
(
4
,
$i
);
$i
++
;
$i
++
;
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
assertEquals
(
5
,
$i
);
$this
->
assertEquals
(
5
,
$i
);
}
}
...
@@ -115,26 +115,26 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
...
@@ -115,26 +115,26 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
{
{
$i
=
0
;
$i
=
0
;
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
before
(
function
()
use
(
&
$i
)
{
$app
->
before
(
function
()
use
(
&
$i
)
{
$i
++
;
$i
++
;
});
});
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
();
throw
new
\RuntimeException
();
});
});
$app
lication
->
after
(
function
()
use
(
&
$i
)
{
$app
->
after
(
function
()
use
(
&
$i
)
{
$i
++
;
$i
++
;
});
});
$app
lication
->
error
(
function
()
{
$app
->
error
(
function
()
{
return
'error handled'
;
return
'error handled'
;
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
assertEquals
(
2
,
$i
);
$this
->
assertEquals
(
2
,
$i
);
}
}
...
@@ -143,22 +143,22 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
...
@@ -143,22 +143,22 @@ class BeforeAfterFilterTest extends \PHPUnit_Framework_TestCase
{
{
$i
=
0
;
$i
=
0
;
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
before
(
function
()
use
(
&
$i
)
{
$app
->
before
(
function
()
use
(
&
$i
)
{
$i
++
;
$i
++
;
});
});
$app
lication
->
after
(
function
()
use
(
&
$i
)
{
$app
->
after
(
function
()
use
(
&
$i
)
{
$i
++
;
$i
++
;
});
});
$app
lication
->
error
(
function
()
{
$app
->
error
(
function
()
{
return
'error handled'
;
return
'error handled'
;
});
});
$request
=
Request
::
create
(
'/nowhere'
);
$request
=
Request
::
create
(
'/nowhere'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
assertEquals
(
2
,
$i
);
$this
->
assertEquals
(
2
,
$i
);
}
}
...
...
tests/Silex/Tests/ControllerCollectionTest.php
View file @
fbb5a69d
...
@@ -15,6 +15,7 @@ use Silex\Application;
...
@@ -15,6 +15,7 @@ use Silex\Application;
use
Silex\Controller
;
use
Silex\Controller
;
use
Silex\ControllerCollection
;
use
Silex\ControllerCollection
;
use
Silex\Exception\ControllerFrozenException
;
use
Silex\Exception\ControllerFrozenException
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\Routing\RouteCollection
;
use
Symfony\Component\Routing\RouteCollection
;
...
...
tests/Silex/Tests/ControllerTest.php
View file @
fbb5a69d
...
@@ -12,6 +12,7 @@
...
@@ -12,6 +12,7 @@
namespace
Silex\Tests
;
namespace
Silex\Tests
;
use
Silex\Controller
;
use
Silex\Controller
;
use
Symfony\Component\Routing\Route
;
use
Symfony\Component\Routing\Route
;
/**
/**
...
...
tests/Silex/Tests/ErrorHandlerTest.php
View file @
fbb5a69d
...
@@ -25,15 +25,15 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
...
@@ -25,15 +25,15 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
{
{
public
function
testNoErrorHandler
()
public
function
testNoErrorHandler
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
(
'foo exception'
);
throw
new
\RuntimeException
(
'foo exception'
);
});
});
try
{
try
{
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
fail
(
'->handle() should not catch exceptions where no error handler was supplied'
);
$this
->
fail
(
'->handle() should not catch exceptions where no error handler was supplied'
);
}
catch
(
\RuntimeException
$e
)
{
}
catch
(
\RuntimeException
$e
)
{
$this
->
assertEquals
(
'foo exception'
,
$e
->
getMessage
());
$this
->
assertEquals
(
'foo exception'
,
$e
->
getMessage
());
...
@@ -42,71 +42,71 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
...
@@ -42,71 +42,71 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
public
function
testOneErrorHandler
()
public
function
testOneErrorHandler
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
(
'foo exception'
);
throw
new
\RuntimeException
(
'foo exception'
);
});
});
$app
lication
->
error
(
function
(
$e
)
{
$app
->
error
(
function
(
$e
)
{
return
new
Response
(
'foo exception handler'
);
return
new
Response
(
'foo exception handler'
);
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/foo'
,
'foo exception handler'
);
$this
->
checkRouteResponse
(
$app
,
'/foo'
,
'foo exception handler'
);
}
}
public
function
testMultipleErrorHandlers
()
public
function
testMultipleErrorHandlers
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
(
'foo exception'
);
throw
new
\RuntimeException
(
'foo exception'
);
});
});
$errors
=
0
;
$errors
=
0
;
$app
lication
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$app
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$errors
++
;
$errors
++
;
});
});
$app
lication
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$app
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$errors
++
;
$errors
++
;
});
});
$app
lication
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$app
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$errors
++
;
$errors
++
;
return
new
Response
(
'foo exception handler'
);
return
new
Response
(
'foo exception handler'
);
});
});
$app
lication
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$app
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
// should not execute
// should not execute
$errors
++
;
$errors
++
;
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/foo'
,
'foo exception handler'
,
'should return the first response returned by an exception handler'
);
$this
->
checkRouteResponse
(
$app
,
'/foo'
,
'foo exception handler'
,
'should return the first response returned by an exception handler'
);
$this
->
assertEquals
(
3
,
$errors
,
'should execute error handlers until a response is returned'
);
$this
->
assertEquals
(
3
,
$errors
,
'should execute error handlers until a response is returned'
);
}
}
public
function
testNoResponseErrorHandler
()
public
function
testNoResponseErrorHandler
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
(
'foo exception'
);
throw
new
\RuntimeException
(
'foo exception'
);
});
});
$errors
=
0
;
$errors
=
0
;
$app
lication
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$app
->
error
(
function
(
$e
)
use
(
&
$errors
)
{
$errors
++
;
$errors
++
;
});
});
try
{
try
{
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
$this
->
fail
(
'->handle() should not catch exceptions where an empty error handler was supplied'
);
$this
->
fail
(
'->handle() should not catch exceptions where an empty error handler was supplied'
);
}
catch
(
\RuntimeException
$e
)
{
}
catch
(
\RuntimeException
$e
)
{
$this
->
assertEquals
(
'foo exception'
,
$e
->
getMessage
());
$this
->
assertEquals
(
'foo exception'
,
$e
->
getMessage
());
...
@@ -117,45 +117,45 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
...
@@ -117,45 +117,45 @@ class ErrorHandlerTest extends \PHPUnit_Framework_TestCase
public
function
testStringResponseErrorHandler
()
public
function
testStringResponseErrorHandler
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
(
'foo exception'
);
throw
new
\RuntimeException
(
'foo exception'
);
});
});
$app
lication
->
error
(
function
(
$e
)
{
$app
->
error
(
function
(
$e
)
{
return
'foo exception handler'
;
return
'foo exception handler'
;
});
});
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/foo'
,
'foo exception handler'
,
'should accept a string response from the error handler'
);
$this
->
checkRouteResponse
(
$app
,
'/foo'
,
'foo exception handler'
,
'should accept a string response from the error handler'
);
}
}
public
function
testErrorHandlerException
()
public
function
testErrorHandlerException
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
throw
new
\RuntimeException
(
'foo exception'
);
throw
new
\RuntimeException
(
'foo exception'
);
});
});
$app
lication
->
error
(
function
(
$e
)
{
$app
->
error
(
function
(
$e
)
{
throw
new
\RuntimeException
(
'foo exception handler exception'
);
throw
new
\RuntimeException
(
'foo exception handler exception'
);
});
});
try
{
try
{
$request
=
Request
::
create
(
'/foo'
);
$request
=
Request
::
create
(
'/foo'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/foo'
,
'foo exception handler'
,
'should accept a string response from the error handler'
);
$this
->
checkRouteResponse
(
$app
,
'/foo'
,
'foo exception handler'
,
'should accept a string response from the error handler'
);
$this
->
fail
(
'->handle() should not catch exceptions thrown from an error handler'
);
$this
->
fail
(
'->handle() should not catch exceptions thrown from an error handler'
);
}
catch
(
\RuntimeException
$e
)
{
}
catch
(
\RuntimeException
$e
)
{
$this
->
assertEquals
(
'foo exception handler exception'
,
$e
->
getMessage
());
$this
->
assertEquals
(
'foo exception handler exception'
,
$e
->
getMessage
());
}
}
}
}
protected
function
checkRouteResponse
(
$app
lication
,
$path
,
$expectedContent
,
$method
=
'get'
,
$message
=
null
)
protected
function
checkRouteResponse
(
$app
,
$path
,
$expectedContent
,
$method
=
'get'
,
$message
=
null
)
{
{
$request
=
Request
::
create
(
$path
,
$method
);
$request
=
Request
::
create
(
$path
,
$method
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
$expectedContent
,
$response
->
getContent
(),
$message
);
$this
->
assertEquals
(
$expectedContent
,
$response
->
getContent
(),
$message
);
}
}
}
}
tests/Silex/Tests/FunctionalTest.php
View file @
fbb5a69d
...
@@ -22,20 +22,20 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
...
@@ -22,20 +22,20 @@ class FunctionalTest extends \PHPUnit_Framework_TestCase
{
{
public
function
testBind
()
public
function
testBind
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
get
(
'/'
,
function
()
{
$app
->
get
(
'/'
,
function
()
{
return
'hello'
;
return
'hello'
;
})
})
->
bind
(
'homepage'
);
->
bind
(
'homepage'
);
$app
lication
->
get
(
'/foo'
,
function
()
{
$app
->
get
(
'/foo'
,
function
()
{
return
'foo'
;
return
'foo'
;
})
})
->
bind
(
'foo_abc'
);
->
bind
(
'foo_abc'
);
$app
lication
->
flush
();
$app
->
flush
();
$routes
=
$app
lication
[
'routes'
];
$routes
=
$app
[
'routes'
];
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\Route'
,
$routes
->
get
(
'homepage'
));
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\Route'
,
$routes
->
get
(
'homepage'
));
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\Route'
,
$routes
->
get
(
'foo_abc'
));
$this
->
assertInstanceOf
(
'Symfony\Component\Routing\Route'
,
$routes
->
get
(
'foo_abc'
));
}
}
...
...
tests/Silex/Tests/RouterTest.php
View file @
fbb5a69d
...
@@ -27,72 +27,72 @@ class RouterTest extends \PHPUnit_Framework_TestCase
...
@@ -27,72 +27,72 @@ class RouterTest extends \PHPUnit_Framework_TestCase
{
{
public
function
testMapRouting
()
public
function
testMapRouting
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
return
'foo'
;
return
'foo'
;
});
});
$app
lication
->
match
(
'/bar'
,
function
()
{
$app
->
match
(
'/bar'
,
function
()
{
return
'bar'
;
return
'bar'
;
});
});
$app
lication
->
match
(
'/'
,
function
()
{
$app
->
match
(
'/'
,
function
()
{
return
'root'
;
return
'root'
;
});
});
$this
->
checkRouteResponse
(
$app
lication
,
'/foo'
,
'foo'
);
$this
->
checkRouteResponse
(
$app
,
'/foo'
,
'foo'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/bar'
,
'bar'
);
$this
->
checkRouteResponse
(
$app
,
'/bar'
,
'bar'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/'
,
'root'
);
$this
->
checkRouteResponse
(
$app
,
'/'
,
'root'
);
}
}
public
function
testStatusCode
()
public
function
testStatusCode
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
put
(
'/created'
,
function
()
{
$app
->
put
(
'/created'
,
function
()
{
return
new
Response
(
''
,
201
);
return
new
Response
(
''
,
201
);
});
});
$app
lication
->
match
(
'/forbidden'
,
function
()
{
$app
->
match
(
'/forbidden'
,
function
()
{
return
new
Response
(
''
,
403
);
return
new
Response
(
''
,
403
);
});
});
$app
lication
->
match
(
'/not_found'
,
function
()
{
$app
->
match
(
'/not_found'
,
function
()
{
return
new
Response
(
''
,
404
);
return
new
Response
(
''
,
404
);
});
});
$request
=
Request
::
create
(
'/created'
,
'put'
);
$request
=
Request
::
create
(
'/created'
,
'put'
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
201
,
$response
->
getStatusCode
());
$this
->
assertEquals
(
201
,
$response
->
getStatusCode
());
$request
=
Request
::
create
(
'/forbidden'
);
$request
=
Request
::
create
(
'/forbidden'
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
403
,
$response
->
getStatusCode
());
$this
->
assertEquals
(
403
,
$response
->
getStatusCode
());
$request
=
Request
::
create
(
'/not_found'
);
$request
=
Request
::
create
(
'/not_found'
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
404
,
$response
->
getStatusCode
());
$this
->
assertEquals
(
404
,
$response
->
getStatusCode
());
}
}
public
function
testRedirect
()
public
function
testRedirect
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/redirect'
,
function
()
{
$app
->
match
(
'/redirect'
,
function
()
{
return
new
RedirectResponse
(
'/target'
);
return
new
RedirectResponse
(
'/target'
);
});
});
$app
lication
->
match
(
'/redirect2'
,
function
()
use
(
$application
)
{
$app
->
match
(
'/redirect2'
,
function
()
use
(
$app
)
{
return
$app
lication
->
redirect
(
'/target2'
);
return
$app
->
redirect
(
'/target2'
);
});
});
$request
=
Request
::
create
(
'/redirect'
);
$request
=
Request
::
create
(
'/redirect'
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target'
));
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target'
));
$request
=
Request
::
create
(
'/redirect2'
);
$request
=
Request
::
create
(
'/redirect2'
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target2'
));
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target2'
));
}
}
...
@@ -101,68 +101,68 @@ class RouterTest extends \PHPUnit_Framework_TestCase
...
@@ -101,68 +101,68 @@ class RouterTest extends \PHPUnit_Framework_TestCase
*/
*/
public
function
testMissingRoute
()
public
function
testMissingRoute
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$request
=
Request
::
create
(
'/baz'
);
$request
=
Request
::
create
(
'/baz'
);
$app
lication
->
handle
(
$request
);
$app
->
handle
(
$request
);
}
}
public
function
testMethodRouting
()
public
function
testMethodRouting
()
{
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
match
(
'/foo'
,
function
()
{
$app
->
match
(
'/foo'
,
function
()
{
return
'foo'
;
return
'foo'
;
});
});
$app
lication
->
match
(
'/bar'
,
function
()
{
$app
->
match
(
'/bar'
,
function
()
{
return
'bar'
;
return
'bar'
;
},
'GET|POST'
);
},
'GET|POST'
);
$app
lication
->
get
(
'/resource'
,
function
()
{
$app
->
get
(
'/resource'
,
function
()
{
return
'get resource'
;
return
'get resource'
;
});
});
$app
lication
->
post
(
'/resource'
,
function
()
{
$app
->
post
(
'/resource'
,
function
()
{
return
'post resource'
;
return
'post resource'
;
});
});
$app
lication
->
put
(
'/resource'
,
function
()
{
$app
->
put
(
'/resource'
,
function
()
{
return
'put resource'
;
return
'put resource'
;
});
});
$app
lication
->
delete
(
'/resource'
,
function
()
{
$app
->
delete
(
'/resource'
,
function
()
{
return
'delete resource'
;
return
'delete resource'
;
});
});
$this
->
checkRouteResponse
(
$app
lication
,
'/foo'
,
'foo'
);
$this
->
checkRouteResponse
(
$app
,
'/foo'
,
'foo'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/bar'
,
'bar'
);
$this
->
checkRouteResponse
(
$app
,
'/bar'
,
'bar'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/bar'
,
'bar'
,
'post'
);
$this
->
checkRouteResponse
(
$app
,
'/bar'
,
'bar'
,
'post'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/resource'
,
'get resource'
);
$this
->
checkRouteResponse
(
$app
,
'/resource'
,
'get resource'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/resource'
,
'post resource'
,
'post'
);
$this
->
checkRouteResponse
(
$app
,
'/resource'
,
'post resource'
,
'post'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/resource'
,
'put resource'
,
'put'
);
$this
->
checkRouteResponse
(
$app
,
'/resource'
,
'put resource'
,
'put'
);
$this
->
checkRouteResponse
(
$app
lication
,
'/resource'
,
'delete resource'
,
'delete'
);
$this
->
checkRouteResponse
(
$app
,
'/resource'
,
'delete resource'
,
'delete'
);
}
}
public
function
testRequestShouldBeStoredRegardlessOfRouting
()
{
public
function
testRequestShouldBeStoredRegardlessOfRouting
()
{
$app
lication
=
new
Application
();
$app
=
new
Application
();
$app
lication
->
get
(
'/foo'
,
function
()
use
(
$application
)
{
$app
->
get
(
'/foo'
,
function
()
use
(
$app
)
{
return
new
Response
(
$app
lication
[
'request'
]
->
getRequestUri
());
return
new
Response
(
$app
[
'request'
]
->
getRequestUri
());
});
});
$app
lication
->
error
(
function
(
$e
)
use
(
$application
)
{
$app
->
error
(
function
(
$e
)
use
(
$app
)
{
return
new
Response
(
$app
lication
[
'request'
]
->
getRequestUri
());
return
new
Response
(
$app
[
'request'
]
->
getRequestUri
());
});
});
foreach
(
array
(
'/foo'
,
'/bar'
)
as
$path
)
{
foreach
(
array
(
'/foo'
,
'/bar'
)
as
$path
)
{
$request
=
Request
::
create
(
$path
);
$request
=
Request
::
create
(
$path
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertContains
(
$path
,
$response
->
getContent
());
$this
->
assertContains
(
$path
,
$response
->
getContent
());
}
}
}
}
protected
function
checkRouteResponse
(
$app
lication
,
$path
,
$expectedContent
,
$method
=
'get'
,
$message
=
null
)
protected
function
checkRouteResponse
(
$app
,
$path
,
$expectedContent
,
$method
=
'get'
,
$message
=
null
)
{
{
$request
=
Request
::
create
(
$path
,
$method
);
$request
=
Request
::
create
(
$path
,
$method
);
$response
=
$app
lication
->
handle
(
$request
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
$expectedContent
,
$response
->
getContent
(),
$message
);
$this
->
assertEquals
(
$expectedContent
,
$response
->
getContent
(),
$message
);
}
}
}
}
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