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
5ecfcbe1
Commit
5ecfcbe1
authored
Jan 02, 2011
by
Igor Wiedler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial test suite
parent
451dea2a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
256 additions
and
0 deletions
+256
-0
README.md
README.md
+6
-0
phpunit.xml
phpunit.xml
+19
-0
tests/Silex/Tests/FrameworkTest.php
tests/Silex/Tests/FrameworkTest.php
+215
-0
tests/bootstrap.php
tests/bootstrap.php
+16
-0
No files found.
README.md
View file @
5ecfcbe1
...
...
@@ -33,6 +33,11 @@ Installation
Installing Silex is as easy as it can get. Download the
[
`Silex.phar`
][
2
]
file
and you're done!
Test Suite
----------------
You can run the
[
PHPUnit
][
3
]
test suite by running
`phpunit`
.
More Information
----------------
...
...
@@ -46,3 +51,4 @@ Silex is licensed under the MIT license.
[
1
]:
http://symfony-reloaded.org/
[
2
]:
http://github.com/fabpot/silex/blob/master/silex.phar
[
3
]:
https://github.com/sebastianbergmann/phpunit
phpunit.xml
0 → 100644
View file @
5ecfcbe1
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals=
"false"
backupStaticAttributes=
"false"
colors=
"false"
convertErrorsToExceptions=
"true"
convertNoticesToExceptions=
"true"
convertWarningsToExceptions=
"true"
processIsolation=
"false"
stopOnFailure=
"false"
syntaxCheck=
"false"
bootstrap=
"tests/bootstrap.php"
>
<testsuites>
<testsuite
name=
"Silex Test Suite"
>
<directory>
./tests/Silex/
</directory>
</testsuite>
</testsuites>
</phpunit>
tests/Silex/Tests/FrameworkTest.php
0 → 100644
View file @
5ecfcbe1
<?php
namespace
Silex\Tests
;
use
Silex\Framework
;
use
Symfony\Component\HttpFoundation\Request
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpKernel\Exception\NotFoundHttpException
;
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.org>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
/**
* The Silex framework class.
*
* @author Fabien Potencier <fabien.potencier@symfony-project.org>
*/
class
FrameworkTest
extends
\PHPUnit_Framework_TestCase
{
public
function
testCreate
()
{
$framework
=
Framework
::
create
();
$this
->
assertInstanceOf
(
'Silex\Framework'
,
$framework
,
"Framework::create() must return instance of Framework"
);
}
public
function
testMapRouting
()
{
$framework
=
Framework
::
create
(
array
(
'/foo'
=>
function
()
{
return
'foo'
;
},
'/bar'
=>
function
()
{
return
'bar'
;
},
'/'
=>
function
()
{
return
'root'
;
},
));
$this
->
checkRouteResponse
(
$framework
,
'/foo'
,
'foo'
);
$this
->
checkRouteResponse
(
$framework
,
'/bar'
,
'bar'
);
$this
->
checkRouteResponse
(
$framework
,
'/'
,
'root'
);
}
public
function
testMapRoutingMethods
()
{
$framework
=
Framework
::
create
(
array
(
'GET /foo'
=>
function
()
{
return
'foo'
;
},
'PUT|DELETE /bar'
=>
function
()
{
return
'bar'
;
},
'/'
=>
function
()
{
return
'root'
;
},
));
// foo route
$this
->
checkRouteResponse
(
$framework
,
'/foo'
,
'foo'
);
// bar route
$this
->
checkRouteResponse
(
$framework
,
'/bar'
,
'bar'
,
'put'
);
$this
->
checkRouteResponse
(
$framework
,
'/bar'
,
'bar'
,
'delete'
);
// root route
$this
->
checkRouteResponse
(
$framework
,
'/'
,
'root'
);
$this
->
checkRouteResponse
(
$framework
,
'/'
,
'root'
,
'post'
);
$this
->
checkRouteResponse
(
$framework
,
'/'
,
'root'
,
'put'
);
$this
->
checkRouteResponse
(
$framework
,
'/'
,
'root'
,
'delete'
);
try
{
$request
=
Request
::
create
(
'http://test.com/bar'
);
$framework
->
handle
(
$request
);
$this
->
fail
(
'Framework must reject HTTP GET method to /bar'
);
}
catch
(
NotFoundHttpException
$expected
)
{
}
try
{
$request
=
Request
::
create
(
'http://test.com/bar'
,
'post'
);
$framework
->
handle
(
$request
);
$this
->
fail
(
'Framework must reject HTTP POST method to /bar'
);
}
catch
(
NotFoundHttpException
$expected
)
{
}
}
public
function
testMapRoutingParameters
()
{
$framework
=
Framework
::
create
(
array
(
'/hello'
=>
function
()
{
return
"Hello anon"
;
},
'/hello/:name'
=>
function
(
$name
)
{
return
"Hello
$name
"
;
},
'/goodbye/:name'
=>
function
(
$name
)
{
return
"Goodbye
$name
"
;
},
'/tell/:name/:message'
=>
function
(
$message
,
$name
)
{
return
"Message for
$name
:
$message
"
;
},
'/'
=>
function
()
{
return
'root'
;
},
));
$this
->
checkRouteResponse
(
$framework
,
'/hello'
,
'Hello anon'
);
$this
->
checkRouteResponse
(
$framework
,
'/hello/alice'
,
'Hello alice'
);
$this
->
checkRouteResponse
(
$framework
,
'/hello/bob'
,
'Hello bob'
);
$this
->
checkRouteResponse
(
$framework
,
'/goodbye/alice'
,
'Goodbye alice'
);
$this
->
checkRouteResponse
(
$framework
,
'/goodbye/bob'
,
'Goodbye bob'
);
$this
->
checkRouteResponse
(
$framework
,
'/tell/bob/secret'
,
'Message for bob: secret'
);
$this
->
checkRouteResponse
(
$framework
,
'/'
,
'root'
);
}
public
function
testStatusCode
()
{
$framework
=
Framework
::
create
(
array
(
'PUT /created'
=>
function
()
{
return
new
Response
(
''
,
201
);
},
'/forbidden'
=>
function
()
{
return
new
Response
(
''
,
403
);
},
'/not_found'
=>
function
()
{
return
new
Response
(
''
,
404
);
},
));
$request
=
Request
::
create
(
'http://test.com/created'
,
'put'
);
$response
=
$framework
->
handle
(
$request
);
$this
->
assertEquals
(
201
,
$response
->
getStatusCode
());
$request
=
Request
::
create
(
'http://test.com/forbidden'
);
$response
=
$framework
->
handle
(
$request
);
$this
->
assertEquals
(
403
,
$response
->
getStatusCode
());
$request
=
Request
::
create
(
'http://test.com/not_found'
);
$response
=
$framework
->
handle
(
$request
);
$this
->
assertEquals
(
404
,
$response
->
getStatusCode
());
}
public
function
testRedirect
()
{
$framework
=
Framework
::
create
(
array
(
'/redirect'
=>
function
()
{
$response
=
new
Response
();
$response
->
setRedirect
(
'/target'
);
return
$response
;
},
));
$request
=
Request
::
create
(
'http://test.com/redirect'
);
$response
=
$framework
->
handle
(
$request
);
$this
->
assertTrue
(
$response
->
isRedirected
(
'/target'
));
}
/**
* @expectedException Symfony\Component\HttpKernel\Exception\NotFoundHttpException
*/
public
function
testMissingRoute
()
{
$framework
=
Framework
::
create
();
$request
=
Request
::
create
(
'http://test.com/baz'
);
$framework
->
handle
(
$request
);
}
public
function
testMethodRouting
()
{
$framework
=
Framework
::
create
()
->
match
(
'/foo'
,
function
()
{
return
'foo'
;
})
->
match
(
'/bar'
,
function
()
{
return
'bar'
;
},
'GET|POST'
)
->
get
(
'/resource'
,
function
()
{
return
'get resource'
;
})
->
post
(
'/resource'
,
function
()
{
return
'post resource'
;
})
->
put
(
'/resource'
,
function
()
{
return
'put resource'
;
})
->
delete
(
'/resource'
,
function
()
{
return
'delete resource'
;
});
$this
->
checkRouteResponse
(
$framework
,
'/foo'
,
'foo'
);
$this
->
checkRouteResponse
(
$framework
,
'/bar'
,
'bar'
);
$this
->
checkRouteResponse
(
$framework
,
'/bar'
,
'bar'
,
'post'
);
$this
->
checkRouteResponse
(
$framework
,
'/resource'
,
'get resource'
);
$this
->
checkRouteResponse
(
$framework
,
'/resource'
,
'post resource'
,
'post'
);
$this
->
checkRouteResponse
(
$framework
,
'/resource'
,
'put resource'
,
'put'
);
$this
->
checkRouteResponse
(
$framework
,
'/resource'
,
'delete resource'
,
'delete'
);
}
protected
function
checkRouteResponse
(
$framework
,
$path
,
$expectedContent
,
$method
=
'get'
,
$message
=
null
)
{
$request
=
Request
::
create
(
'http://test.com'
.
$path
,
$method
);
$response
=
$framework
->
handle
(
$request
);
$this
->
assertEquals
(
$expectedContent
,
$response
->
getContent
(),
$message
);
}
}
tests/bootstrap.php
0 → 100644
View file @
5ecfcbe1
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien.potencier@symfony-project.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
if
(
file_exists
(
$file
=
__DIR__
.
'/../src/autoload.php'
))
{
require_once
$file
;
}
elseif
(
file_exists
(
$file
=
__DIR__
.
'/../src/autoload.php.dist'
))
{
require_once
$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