-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: Restore tests and update them according to latest changes.
- Loading branch information
Showing
5 changed files
with
166 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
<?php | ||
|
||
/** | ||
* For the full copyright and license information, please view | ||
* the LICENSE file that was distributed with this source code. | ||
* | ||
* @see https://github.com/ecphp | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace spec\EcPhp\CasLib\Utils; | ||
|
||
use EcPhp\CasLib\Exception\CasExceptionInterface; | ||
use Nyholm\Psr7\Response; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class ResponseSpec extends ObjectBehavior | ||
{ | ||
public function it_convert_a_json_response() | ||
{ | ||
$body = <<< 'EOF' | ||
{ | ||
"serviceResponse": { | ||
"authenticationSuccess": { | ||
"user": "username" | ||
} | ||
} | ||
} | ||
EOF; | ||
|
||
$response = new Response( | ||
200, | ||
[ | ||
'Content-Type' => 'application/json', | ||
], | ||
$body | ||
); | ||
|
||
$this | ||
->toArray($response) | ||
->shouldReturn([ | ||
'serviceResponse' => [ | ||
'authenticationSuccess' => [ | ||
'user' => 'username', | ||
], | ||
], | ||
]); | ||
} | ||
|
||
public function it_convert_a_xml_response() | ||
{ | ||
$body = <<< 'EOF' | ||
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"> | ||
<cas:authenticationSuccess> | ||
<cas:user>username</cas:user> | ||
</cas:authenticationSuccess> | ||
</cas:serviceResponse> | ||
EOF; | ||
|
||
$response = new Response( | ||
200, | ||
[ | ||
'Content-Type' => 'application/xml', | ||
], | ||
$body | ||
); | ||
|
||
$this | ||
->toArray($response) | ||
->shouldReturn([ | ||
'serviceResponse' => [ | ||
'authenticationSuccess' => [ | ||
'user' => 'username', | ||
], | ||
], | ||
]); | ||
} | ||
|
||
public function it_throws_when_content_type_header_is_missing() | ||
{ | ||
$body = <<< 'EOF' | ||
<cas:serviceResponse xmlns:cas="http://www.yale.edu/tp/cas"> | ||
<cas:authenticationSuccess> | ||
<cas:user>username</cas:user> | ||
</cas:authenticationSuccess> | ||
</cas:serviceResponse> | ||
EOF; | ||
|
||
$response = new Response( | ||
200, | ||
[], | ||
$body | ||
); | ||
|
||
$this | ||
->shouldThrow(CasExceptionInterface::class) | ||
->during('toArray', [$response]); | ||
} | ||
} |