baseUrl = $baseUrl; // in case of ci deployment we take the server url from the environment $testServerUrl = getenv('TEST_SERVER_URL'); if ($testServerUrl !== false) { $this->baseUrl = substr($testServerUrl, 0, -5); } } /** @BeforeScenario */ public function setUpScenario(): void { $this->client = $this->createGuzzleInstance(); } /** * Create a Guzzle client with a higher truncateAt value to read full error responses. */ private function createGuzzleInstance(): Client { $bodySummarizer = new BodySummarizer(2048); $stack = new HandlerStack(Utils::chooseHandler()); $stack->push(Middleware::httpErrors($bodySummarizer), 'http_errors'); $stack->push(Middleware::redirect(), 'allow_redirects'); $stack->push(Middleware::cookies(), 'cookies'); $stack->push(Middleware::prepareBody(), 'prepare_body'); return new Client(['handler' => $stack]); } /** * @When searching for a principal matching :match * @param string $match * @throws \Exception */ public function principalPropertySearch(string $match) { $davUrl = $this->baseUrl . '/remote.php/dav/'; $user = 'admin'; $password = 'admin'; $this->response = $this->client->request( 'REPORT', $davUrl, [ 'body' => ' ' . $match . ' ', 'auth' => [ $user, $password, ], 'headers' => [ 'Content-Type' => 'application/xml; charset=UTF-8', 'Depth' => '0', ], ] ); } /** * @Then The search HTTP status code should be :code * @param string $code * @throws \Exception */ public function theHttpStatusCodeShouldBe(string $code): void { if ((int)$code !== $this->response->getStatusCode()) { throw new \Exception('Expected ' . (int)$code . ' got ' . $this->response->getStatusCode()); } } /** * @Then The search response should contain :needle * @param string $needle * @throws \Exception */ public function theResponseShouldContain(string $needle): void { $body = $this->response->getBody()->getContents(); if (str_contains($body, $needle) === false) { throw new \Exception('Response does not contain "' . $needle . '"'); } } }