Skip to content

Commit

Permalink
Prepare Members 2.5 Sealing (#103)
Browse files Browse the repository at this point in the history
* prepare members 2.5 sealing

* remove empty tests

* allow better exception handling in rest client

* assert right https header

* assert right https header

* fix test include

* fix travis
  • Loading branch information
solverat authored Jul 18, 2019
1 parent 8c8e4bd commit 490dd41
Show file tree
Hide file tree
Showing 7 changed files with 112 additions and 16 deletions.
9 changes: 5 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
sudo: required
sudo: true
language: php
addons:
chrome: stable
mariadb: '10.1'

mariadb: '10.2'
services:
- mysql
env:
global:
- PIMCORE_ENVIRONMENT=test
Expand Down Expand Up @@ -100,7 +101,7 @@ after_failure:

script:
- '$HOME/chromedriver --url-base=/wd/hub &'
- 'php ${TRAVIS_BUILD_DIR}/bin/console server:start 127.0.0.1:8080'
- 'php ${TRAVIS_BUILD_DIR}/bin/console server:start 127.0.0.1:8080 -d web'
- 'php ${TRAVIS_BUILD_DIR}/bin/console server:status'
- _etc/travis/script

Expand Down
1 change: 1 addition & 0 deletions tests/_etc/travis/install
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ do
done

## install composer dependencies
rm composer.lock

COMPOSER_MEMORY_LIMIT=-1 composer install --no-scripts

Expand Down
64 changes: 64 additions & 0 deletions tests/_support/Helper/Rest/BrowserKitRestClient.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php

namespace DachcomBundle\Test\Helper\Rest;

use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use Symfony\Component\BrowserKit\Request as BrowserKitRequest;
use Symfony\Component\BrowserKit\Response as BrowserKitResponse;

class BrowserKitRestClient extends \Pimcore\Tests\Rest\BrowserKitRestClient
{
/**
* @inheritDoc
*/
public function getResponse($method, $uri, array $parameters = [], array $files = [], array $server = [], $content = null)
{
$uri = $this->prepareUri($uri);
$parameters = $this->prepareParameters($parameters);
$server = $this->prepareHeaders($server);

if (count($parameters) > 0) {
$query = http_build_query($parameters);

if (false === strpos($uri, '?')) {
$uri .= '?' . $query;
} else {
$uri .= '&' . $query;
}
}

codecept_debug('[BrowserKitRestClient] Requesting URI ' . $uri);

$this->client->request($method, $uri, $parameters, $files, $server, $content);

/** @var BrowserKitRequest $browserKitRequest */
$browserKitRequest = $this->client->getInternalRequest();

/** @var BrowserKitResponse $response */
$browserKitResponse = $this->client->getInternalResponse();

$headers = $browserKitRequest->getServer();
if (isset($headers['HTTPS'])) {
$headers['HTTPS'] = (string) $headers['HTTPS'];
}

$request = new Request(
$browserKitRequest->getMethod(),
$browserKitRequest->getUri(),
$headers,
$browserKitRequest->getContent()
);

$response = new Response(
$browserKitResponse->getStatus(),
$browserKitResponse->getHeaders(),
$browserKitResponse->getContent()
);

$this->lastRequest = $request;
$this->lastResponse = $response;

return $response;
}
}
Empty file.
39 changes: 39 additions & 0 deletions tests/rest/AbstractRestTestCase.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace DachcomBundle\Test\rest;

use DachcomBundle\Test\Helper\Rest\BrowserKitRestClient;
use DachcomBundle\Test\Util\MembersHelper;
use Pimcore\Tests\Test\RestTestCase;

abstract class AbstractRestTestCase extends RestTestCase
{
public function setUp()
{
parent::setUp();

$this->restClient = new BrowserKitRestClient($this->tester->getHttpClient());

if ($this->authenticateUser) {
$this->restClient->setApiKey($this->tester->getRestApiKey($this->authenticateUser));
}
}

/**
* Params which will be added to each request
*
* @return array
*/
public function getGlobalRequestParams()
{
return [];
}

protected function _after()
{
MembersHelper::cleanUp();
MembersHelper::reCreateMembersStructure();

parent::_after();
}
}
14 changes: 2 additions & 12 deletions tests/rest/ObjectTest.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,16 @@
<?php

namespace Pimcore\Tests\Rest;
namespace DachcomBundle\Test\rest;

use DachcomBundle\Test\Util\MembersHelper;
use MembersBundle\Adapter\Group\GroupInterface;
use MembersBundle\Adapter\User\UserInterface;
use Pimcore\Model\DataObject\AbstractObject;
use Pimcore\Model\DataObject\MembersGroup;
use Pimcore\Model\DataObject\MembersUser;
use Pimcore\Tests\Test\RestTestCase;
use Pimcore\Tests\Util\TestHelper;

class UserTest extends RestTestCase
class ObjectTest extends AbstractRestTestCase
{
protected function _after()
{
MembersHelper::cleanUp();
MembersHelper::reCreateMembersStructure();

parent::_after();
}

public function testUserCreate()
{
$unsavedObject = new MembersUser();
Expand Down
1 change: 1 addition & 0 deletions tests/rest/_bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
<?php
// Here you can initialize variables that will be available to your tests
include __DIR__ . '/AbstractRestTestCase.php';

0 comments on commit 490dd41

Please sign in to comment.