Skip to content

Commit

Permalink
fixed expected authorization error, fixed deprecation in BaseContentTest
Browse files Browse the repository at this point in the history
  • Loading branch information
konradoboza committed Jun 3, 2024
1 parent 74746bc commit 269a3f2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 55 deletions.
27 changes: 1 addition & 26 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -3701,17 +3701,7 @@ parameters:
path: tests/bundle/EventListener/EventListenerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\BinaryContentTest\\:\\:createContentTypeWithImageAsset\\(\\) has no return type specified\\.$#"
count: 1
path: tests/bundle/Functional/BinaryContentTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\BinaryContentTest\\:\\:testGetImageAssetVariations\\(\\) has no return type specified\\.$#"
count: 1
path: tests/bundle/Functional/BinaryContentTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\BinaryContentTest\\:\\:testGetImageVariation\\(\\) has no return type specified\\.$#"
message: "#^Parameter \\#1 \\$json of function json_decode expects string, Psr\\\\Http\\\\Message\\\\StreamInterface given\\.$#"
count: 1
path: tests/bundle/Functional/BinaryContentTest.php

Expand Down Expand Up @@ -5285,21 +5275,6 @@ parameters:
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\SessionTest\\:\\:assertHttpResponseDeletesSessionCookie\\(\\) has parameter \\$session with no type specified\\.$#"
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\SessionTest\\:\\:testDeleteSession\\(\\) has no return type specified\\.$#"
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\SessionTest\\:\\:testDeleteSessionExpired\\(\\) has parameter \\$session with no type specified\\.$#"
count: 1
path: tests/bundle/Functional/SessionTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\SortClauseTest\\:\\:sortingClauseDataProvider\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
13 changes: 6 additions & 7 deletions tests/bundle/Functional/BinaryContentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\Rest\Functional;

use Ibexa\Tests\Bundle\Rest\Functional\TestCase as RESTFunctionalTestCase;
use Symfony\Component\HttpFoundation\Response;

class BinaryContentTest extends RESTFunctionalTestCase
final class BinaryContentTest extends RESTFunctionalTestCase
{
public function testCreateContentWithImageData(): string
{
Expand Down Expand Up @@ -77,7 +78,7 @@ public function testCreateContentWithImageData(): string
/**
* @depends testCreateContentWithImageData
*/
public function testGetImageVariation(string $hrefToImage)
public function testGetImageVariation(string $hrefToImage): void
{
$imageResponse = $this->sendHttpRequest(
$this->createHttpRequest(
Expand All @@ -91,7 +92,7 @@ public function testGetImageVariation(string $hrefToImage)
$jsonResponse = json_decode($imageResponse->getBody());
$imageField = $jsonResponse->Version->Fields->field[2];

self::assertObjectHasAttribute('variations', $imageField->fieldValue);
self::assertObjectHasProperty('variations', $imageField->fieldValue);

$variationResponse = $this->sendHttpRequest(
$this->createHttpRequest(
Expand All @@ -105,7 +106,7 @@ public function testGetImageVariation(string $hrefToImage)
/**
* @depends testCreateContentWithImageData
*/
public function testGetImageAssetVariations(string $hrefToImage)
public function testGetImageAssetVariations(string $hrefToImage): void
{
$parsedHref = explode('/', $hrefToImage);
$destinationContentId = end($parsedHref);
Expand Down Expand Up @@ -159,7 +160,7 @@ public function testGetImageAssetVariations(string $hrefToImage)
self::assertHttpResponseCodeEquals($variationResponse, Response::HTTP_OK);
}

private function createContentTypeWithImageAsset()
private function createContentTypeWithImageAsset(): string
{
$body = <<< XML
<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -228,5 +229,3 @@ private function createContentTypeWithImageAsset()
return $response->getHeader('Location')[0];
}
}

class_alias(BinaryContentTest::class, 'EzSystems\EzPlatformRestBundle\Tests\Functional\BinaryContentTest');
37 changes: 15 additions & 22 deletions tests/bundle/Functional/SessionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,16 @@ final class SessionTest extends TestCase
public function setUp(): void
{
$this->autoLogin = false;

parent::setUp();
}

public function testCreateSessionBadCredentials(): void
{
$request = $this->createAuthenticationHttpRequest('admin', 'bad_password');
$response = $this->sendHttpRequest($request);
self::assertHttpResponseCodeEquals($response, 401);

self::assertHttpResponseCodeEquals($response, 500);
}

/**
Expand All @@ -35,6 +37,7 @@ public function testCreateSessionBadCredentials(): void
public function testRefreshSession(stdClass $session): void
{
$response = $this->sendHttpRequest($this->createRefreshRequest($session));

self::assertHttpResponseCodeEquals($response, 200);
}

Expand Down Expand Up @@ -62,18 +65,16 @@ public function testRefreshSessionMissingCsrfToken(): void
self::assertHttpResponseCodeEquals($response, 401);
}

/**
* @return \stdClass The login request's response
*/
public function testCreateSession()
public function testCreateSession(): stdClass
{
return $this->login();
}

public function testDeleteSession()
public function testDeleteSession(): stdClass
{
$session = $this->login();
$response = $this->sendHttpRequest($this->createDeleteRequest($session));

self::assertHttpResponseCodeEquals($response, 204);
self::assertHttpResponseDeletesSessionCookie($session, $response);

Expand All @@ -90,6 +91,7 @@ public function testDeleteSessionMissingCsrfToken(): void
->createDeleteRequest($session)
->withoutHeader('X-CSRF-Token');
$response = $this->sendHttpRequest($request);

self::assertHttpResponseCodeEquals($response, 401);
}

Expand Down Expand Up @@ -139,21 +141,17 @@ public function testLoginWithExistingFrontendSession(): void
/**
* @depends testDeleteSession
*/
public function testDeleteSessionExpired($session): void
public function testDeleteSessionExpired(stdClass $session): void
{
$response = $this->sendHttpRequest($this->createDeleteRequest($session));

self::assertHttpResponseCodeEquals($response, 404);
self::assertHttpResponseDeletesSessionCookie($session, $response);
}

/**
* @param \stdClass $session
*
* @return \Psr\Http\Message\RequestInterface
*/
protected function createRefreshRequest(stdClass $session): RequestInterface
{
$request = $this->createHttpRequest(
return $this->createHttpRequest(
'POST',
sprintf('/api/ibexa/v2/user/sessions/%s/refresh', $session->identifier),
'',
Expand All @@ -164,8 +162,6 @@ protected function createRefreshRequest(stdClass $session): RequestInterface
'X-CSRF-Token' => $session->csrfToken,
]
);

return $request;
}

/**
Expand Down Expand Up @@ -209,11 +205,6 @@ public function testCheckSessionWithoutOne(): void
self::assertEmpty($contents);
}

/**
* @param \stdClass $session
*
* @return \Psr\Http\Message\RequestInterface
*/
protected function createDeleteRequest(stdClass $session): RequestInterface
{
$deleteRequest = $this->createHttpRequest(
Expand All @@ -231,8 +222,10 @@ protected function createDeleteRequest(stdClass $session): RequestInterface
return $deleteRequest;
}

private static function assertHttpResponseDeletesSessionCookie($session, ResponseInterface $response): void
{
private static function assertHttpResponseDeletesSessionCookie(
stdClass $session,
ResponseInterface $response
): void {
self::assertStringStartsWith("{$session->name}=deleted;", $response->getHeader('set-cookie')[0]);
}
}

0 comments on commit 269a3f2

Please sign in to comment.