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
acf60818
Commit
acf60818
authored
Jun 19, 2012
by
Fabien Potencier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
added some unit tests
parent
72ac7c5a
Changes
18
Hide whitespace changes
Inline
Side-by-side
Showing
18 changed files
with
662 additions
and
3 deletions
+662
-3
src/Silex/Application/TranslationTrait.php
src/Silex/Application/TranslationTrait.php
+2
-2
src/Silex/Application/TwigTrait.php
src/Silex/Application/TwigTrait.php
+1
-1
tests/Silex/Tests/Application/FormApplication.php
tests/Silex/Tests/Application/FormApplication.php
+19
-0
tests/Silex/Tests/Application/FormTraitTest.php
tests/Silex/Tests/Application/FormTraitTest.php
+47
-0
tests/Silex/Tests/Application/MonologApplication.php
tests/Silex/Tests/Application/MonologApplication.php
+19
-0
tests/Silex/Tests/Application/MonologTraitTest.php
tests/Silex/Tests/Application/MonologTraitTest.php
+58
-0
tests/Silex/Tests/Application/SecurityApplication.php
tests/Silex/Tests/Application/SecurityApplication.php
+19
-0
tests/Silex/Tests/Application/SecurityTraitTest.php
tests/Silex/Tests/Application/SecurityTraitTest.php
+77
-0
tests/Silex/Tests/Application/SwiftmailerApplication.php
tests/Silex/Tests/Application/SwiftmailerApplication.php
+19
-0
tests/Silex/Tests/Application/SwiftmailerTraitTest.php
tests/Silex/Tests/Application/SwiftmailerTraitTest.php
+56
-0
tests/Silex/Tests/Application/TranslationApplication.php
tests/Silex/Tests/Application/TranslationApplication.php
+19
-0
tests/Silex/Tests/Application/TranslationTraitTest.php
tests/Silex/Tests/Application/TranslationTraitTest.php
+58
-0
tests/Silex/Tests/Application/TwigApplication.php
tests/Silex/Tests/Application/TwigApplication.php
+19
-0
tests/Silex/Tests/Application/TwigTraitTest.php
tests/Silex/Tests/Application/TwigTraitTest.php
+92
-0
tests/Silex/Tests/Application/UrlGeneratorApplication.php
tests/Silex/Tests/Application/UrlGeneratorApplication.php
+19
-0
tests/Silex/Tests/Application/UrlGeneratorTraitTest.php
tests/Silex/Tests/Application/UrlGeneratorTraitTest.php
+54
-0
tests/Silex/Tests/Route/SecurityRoute.php
tests/Silex/Tests/Route/SecurityRoute.php
+19
-0
tests/Silex/Tests/Route/SecurityTraitTest.php
tests/Silex/Tests/Route/SecurityTraitTest.php
+65
-0
No files found.
src/Silex/Application/TranslationTrait.php
View file @
acf60818
...
...
@@ -30,7 +30,7 @@ trait TranslationTrait
*/
public
function
trans
(
$id
,
array
$parameters
=
array
(),
$domain
=
'messages'
,
$locale
=
null
)
{
return
$
app
[
'translator'
]
->
trans
(
$id
,
$parameters
,
$domain
,
$locale
);
return
$
this
[
'translator'
]
->
trans
(
$id
,
$parameters
,
$domain
,
$locale
);
}
/**
...
...
@@ -46,6 +46,6 @@ trait TranslationTrait
*/
public
function
transChoice
(
$id
,
$number
,
array
$parameters
=
array
(),
$domain
=
'messages'
,
$locale
=
null
)
{
return
$
app
[
'translator'
]
->
transChoice
(
$id
,
$number
,
$parameters
,
$domain
,
$locale
);
return
$
this
[
'translator'
]
->
transChoice
(
$id
,
$number
,
$parameters
,
$domain
,
$locale
);
}
}
src/Silex/Application/TwigTrait.php
View file @
acf60818
...
...
@@ -42,7 +42,7 @@ trait TwigTrait
if
(
$response
instanceof
StreamedResponse
)
{
$response
->
setCallback
(
function
()
use
(
$twig
,
$view
,
$parameters
)
{
$t
his
[
'twig'
]
->
display
(
$view
,
$parameters
);
$t
wig
->
display
(
$view
,
$parameters
);
});
}
else
{
$response
->
setContent
(
$twig
->
render
(
$view
,
$parameters
));
...
...
tests/Silex/Tests/Application/FormApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
FormApplication
extends
Application
{
use
Application\FormTrait
;
}
tests/Silex/Tests/Application/FormTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\FormServiceProvider
;
/**
* FormTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
FormTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/symfony/form'
))
{
$this
->
markTestSkipped
(
'Form dependency was not installed.'
);
}
}
public
function
testForm
()
{
$this
->
assertInstanceOf
(
'Symfony\Component\Form\FormBuilder'
,
$this
->
createApplication
()
->
form
());
}
public
function
createApplication
()
{
$app
=
new
FormApplication
();
$app
->
register
(
new
FormServiceProvider
());
return
$app
;
}
}
tests/Silex/Tests/Application/MonologApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
MonologApplication
extends
Application
{
use
Application\MonologTrait
;
}
tests/Silex/Tests/Application/MonologTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\MonologServiceProvider
;
use
Monolog\Handler\TestHandler
;
use
Monolog\Logger
;
/**
* MonologTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
MonologTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/monolog/monolog/src'
))
{
$this
->
markTestSkipped
(
'Monolog dependency was not installed.'
);
}
}
public
function
testLog
()
{
$app
=
$this
->
createApplication
();
$app
->
log
(
'Foo'
);
$app
->
log
(
'Bar'
,
array
(),
Logger
::
DEBUG
);
$this
->
assertTrue
(
$app
[
'monolog.handler'
]
->
hasInfo
(
'Foo'
));
$this
->
assertTrue
(
$app
[
'monolog.handler'
]
->
hasDebug
(
'Bar'
));
}
public
function
createApplication
()
{
$app
=
new
MonologApplication
();
$app
->
register
(
new
MonologServiceProvider
(),
array
(
'monolog.handler'
=>
$app
->
share
(
function
()
use
(
$app
)
{
return
new
TestHandler
(
$app
[
'monolog.level'
]);
}),
));
return
$app
;
}
}
tests/Silex/Tests/Application/SecurityApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
SecurityApplication
extends
Application
{
use
Application\SecurityTrait
;
}
tests/Silex/Tests/Application/SecurityTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\SecurityServiceProvider
;
use
Symfony\Component\Security\Core\User\User
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* SecurityTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
SecurityTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/symfony/security'
))
{
$this
->
markTestSkipped
(
'Security dependency was not installed.'
);
}
}
public
function
testUser
()
{
$request
=
Request
::
create
(
'/'
);
$app
=
$this
->
createApplication
();
$app
->
get
(
'/'
,
function
()
{
return
'foo'
;
});
$app
->
handle
(
$request
);
$this
->
assertNull
(
$app
->
user
());
$request
->
headers
->
set
(
'PHP_AUTH_USER'
,
'fabien'
);
$request
->
headers
->
set
(
'PHP_AUTH_PW'
,
'foo'
);
$app
->
handle
(
$request
);
$this
->
assertInstanceOf
(
'Symfony\Component\Security\Core\User\UserInterface'
,
$app
->
user
());
$this
->
assertEquals
(
'fabien'
,
$app
->
user
()
->
getUsername
());
}
public
function
testEncodePassword
()
{
$app
=
$this
->
createApplication
();
$user
=
new
User
(
'foo'
,
'bar'
);
$this
->
assertEquals
(
'5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='
,
$app
->
encodePassword
(
$user
,
'foo'
));
}
public
function
createApplication
()
{
$app
=
new
SecurityApplication
();
$app
->
register
(
new
SecurityServiceProvider
(),
array
(
'security.firewalls'
=>
array
(
'default'
=>
array
(
'http'
=>
true
,
'users'
=>
array
(
'fabien'
=>
array
(
'ROLE_ADMIN'
,
'5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='
),
),
),
),
));
return
$app
;
}
}
tests/Silex/Tests/Application/SwiftmailerApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
SwiftmailerApplication
extends
Application
{
use
Application\SwiftmailerTrait
;
}
tests/Silex/Tests/Application/SwiftmailerTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\SwiftmailerServiceProvider
;
/**
* SwiftmailerTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
SwiftmailerTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/swiftmailer/swiftmailer'
))
{
$this
->
markTestSkipped
(
'Swiftmailer dependency was not installed.'
);
}
}
public
function
testMail
()
{
$app
=
$this
->
createApplication
();
$message
=
$this
->
getMockBuilder
(
'Swift_Message'
)
->
disableOriginalConstructor
()
->
getMock
();
$app
[
'mailer'
]
=
$mailer
=
$this
->
getMockBuilder
(
'Swift_Mailer'
)
->
disableOriginalConstructor
()
->
getMock
();
$mailer
->
expects
(
$this
->
once
())
->
method
(
'send'
)
->
with
(
$message
)
;
$app
->
mail
(
$message
);
}
public
function
createApplication
()
{
$app
=
new
SwiftmailerApplication
();
$app
->
register
(
new
SwiftmailerServiceProvider
());
return
$app
;
}
}
tests/Silex/Tests/Application/TranslationApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
TranslationApplication
extends
Application
{
use
Application\TranslationTrait
;
}
tests/Silex/Tests/Application/TranslationTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\TranslationServiceProvider
;
/**
* TranslationTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
TranslationTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/symfony/translation'
))
{
$this
->
markTestSkipped
(
'Translation dependency was not installed.'
);
}
}
public
function
testTrans
()
{
$app
=
$this
->
createApplication
();
$app
[
'translator'
]
=
$translator
=
$this
->
getMockBuilder
(
'Symfony\Component\Translation\Translator'
)
->
disableOriginalConstructor
()
->
getMock
();
$translator
->
expects
(
$this
->
once
())
->
method
(
'trans'
);
$app
->
trans
(
'foo'
);
}
public
function
testTransChoice
()
{
$app
=
$this
->
createApplication
();
$app
[
'translator'
]
=
$translator
=
$this
->
getMockBuilder
(
'Symfony\Component\Translation\Translator'
)
->
disableOriginalConstructor
()
->
getMock
();
$translator
->
expects
(
$this
->
once
())
->
method
(
'transChoice'
);
$app
->
transChoice
(
'foo'
,
2
);
}
public
function
createApplication
()
{
$app
=
new
TranslationApplication
();
$app
->
register
(
new
TranslationServiceProvider
());
return
$app
;
}
}
tests/Silex/Tests/Application/TwigApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
TwigApplication
extends
Application
{
use
Application\TwigTrait
;
}
tests/Silex/Tests/Application/TwigTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\TwigServiceProvider
;
use
Symfony\Component\HttpFoundation\Response
;
use
Symfony\Component\HttpFoundation\StreamedResponse
;
/**
* TwigTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
TwigTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/twig/twig'
))
{
$this
->
markTestSkipped
(
'Twig dependency was not installed.'
);
}
}
public
function
testRender
()
{
$app
=
$this
->
createApplication
();
$app
[
'twig'
]
=
$mailer
=
$this
->
getMockBuilder
(
'Twig_Environment'
)
->
disableOriginalConstructor
()
->
getMock
();
$mailer
->
expects
(
$this
->
once
())
->
method
(
'render'
)
->
will
(
$this
->
returnValue
(
'foo'
));
$response
=
$app
->
render
(
'view'
);
$this
->
assertEquals
(
'Symfony\Component\HttpFoundation\Response'
,
get_class
(
$response
));
$this
->
assertEquals
(
'foo'
,
$response
->
getContent
());
}
public
function
testRenderKeepResponse
()
{
$app
=
$this
->
createApplication
();
$app
[
'twig'
]
=
$mailer
=
$this
->
getMockBuilder
(
'Twig_Environment'
)
->
disableOriginalConstructor
()
->
getMock
();
$mailer
->
expects
(
$this
->
once
())
->
method
(
'render'
)
->
will
(
$this
->
returnValue
(
'foo'
));
$response
=
$app
->
render
(
'view'
,
array
(),
new
Response
(
''
,
404
));
$this
->
assertEquals
(
404
,
$response
->
getStatusCode
());
}
public
function
testRenderForStream
()
{
$app
=
$this
->
createApplication
();
$app
[
'twig'
]
=
$mailer
=
$this
->
getMockBuilder
(
'Twig_Environment'
)
->
disableOriginalConstructor
()
->
getMock
();
$mailer
->
expects
(
$this
->
once
())
->
method
(
'display'
)
->
will
(
$this
->
returnCallback
(
function
()
{
echo
'foo'
;
}));
$response
=
$app
->
render
(
'view'
,
array
(),
new
StreamedResponse
());
$this
->
assertEquals
(
'Symfony\Component\HttpFoundation\StreamedResponse'
,
get_class
(
$response
));
ob_start
();
$response
->
send
();
$this
->
assertEquals
(
'foo'
,
ob_get_clean
());
}
public
function
testRenderView
()
{
$app
=
$this
->
createApplication
();
$app
[
'twig'
]
=
$mailer
=
$this
->
getMockBuilder
(
'Twig_Environment'
)
->
disableOriginalConstructor
()
->
getMock
();
$mailer
->
expects
(
$this
->
once
())
->
method
(
'render'
);
$app
->
renderView
(
'view'
);
}
public
function
createApplication
()
{
$app
=
new
TwigApplication
();
$app
->
register
(
new
TwigServiceProvider
());
return
$app
;
}
}
tests/Silex/Tests/Application/UrlGeneratorApplication.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
class
UrlGeneratorApplication
extends
Application
{
use
Application\UrlGeneratorTrait
;
}
tests/Silex/Tests/Application/UrlGeneratorTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Application
;
use
Silex\Application
;
use
Silex\Provider\UrlGeneratorServiceProvider
;
/**
* UrlGeneratorTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
UrlGeneratorTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
}
public
function
testUrl
()
{
$app
=
$this
->
createApplication
();
$app
[
'url_generator'
]
=
$translator
=
$this
->
getMockBuilder
(
'Symfony\Component\Routing\Generator\UrlGeneratorInterface'
)
->
disableOriginalConstructor
()
->
getMock
();
$translator
->
expects
(
$this
->
once
())
->
method
(
'generate'
)
->
with
(
'foo'
,
array
(),
true
);
$app
->
url
(
'foo'
);
}
public
function
testPath
()
{
$app
=
$this
->
createApplication
();
$app
[
'url_generator'
]
=
$translator
=
$this
->
getMockBuilder
(
'Symfony\Component\Routing\Generator\UrlGeneratorInterface'
)
->
disableOriginalConstructor
()
->
getMock
();
$translator
->
expects
(
$this
->
once
())
->
method
(
'generate'
)
->
with
(
'foo'
,
array
(),
false
);
$app
->
path
(
'foo'
);
}
public
function
createApplication
()
{
$app
=
new
UrlGeneratorApplication
();
$app
->
register
(
new
UrlGeneratorServiceProvider
());
return
$app
;
}
}
tests/Silex/Tests/Route/SecurityRoute.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Route
;
use
Silex\Route
;
class
SecurityRoute
extends
Route
{
use
Route\SecurityTrait
;
}
tests/Silex/Tests/Route/SecurityTraitTest.php
0 → 100644
View file @
acf60818
<?php
/*
* This file is part of the Silex framework.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* This source file is subject to the MIT license that is bundled
* with this source code in the file LICENSE.
*/
namespace
Silex\Tests\Route
;
use
Silex\Application
;
use
Silex\Provider\SecurityServiceProvider
;
use
Symfony\Component\HttpFoundation\Request
;
/**
* SecurityTrait test cases.
*
* @author Fabien Potencier <fabien@symfony.com>
*/
class
SecurityTraitTest
extends
\PHPUnit_Framework_TestCase
{
public
function
setUp
()
{
if
(
version_compare
(
phpversion
(),
'5.4.0'
,
'<'
))
{
$this
->
markTestSkipped
(
'PHP 5.4 is required for this test'
);
}
if
(
!
is_dir
(
__DIR__
.
'/../../../../vendor/symfony/security'
))
{
$this
->
markTestSkipped
(
'Security dependency was not installed.'
);
}
}
public
function
testSecure
()
{
$app
=
new
Application
();
$app
[
'route_class'
]
=
'Silex\Tests\Route\SecurityRoute'
;
$app
->
register
(
new
SecurityServiceProvider
(),
array
(
'security.firewalls'
=>
array
(
'default'
=>
array
(
'http'
=>
true
,
'users'
=>
array
(
'fabien'
=>
array
(
'ROLE_ADMIN'
,
'5FZ2Z8QIkA7UTZ4BYkoC+GsReLf569mSKDsfods6LYQ8t+a8EW9oaircfMpmaLbPBh4FOBiiFyLfuZmTSUwzZg=='
),
),
),
),
));
$app
->
get
(
'/'
,
function
()
{
return
'foo'
;
})
->
secure
(
'ROLE_ADMIN'
)
;
$request
=
Request
::
create
(
'/'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
401
,
$response
->
getStatusCode
());
$request
=
Request
::
create
(
'/'
);
$request
->
headers
->
set
(
'PHP_AUTH_USER'
,
'fabien'
);
$request
->
headers
->
set
(
'PHP_AUTH_PW'
,
'foo'
);
$response
=
$app
->
handle
(
$request
);
$this
->
assertEquals
(
200
,
$response
->
getStatusCode
());
}
}
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