Skip to content

Commit e78fca9

Browse files
author
Bastian Schwarz
committed
Created more tests
Signed-off-by: Bastian Schwarz <bastian@repareo.de>
1 parent 0a3eaf1 commit e78fca9

15 files changed

Lines changed: 368 additions & 4 deletions

.gitattributes

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,6 @@
1414
/phive.xml export-ignore
1515
/psalm.xml export-ignore
1616

17-
*.php text=auto eol=lf
17+
*.php text=auto eol=lf
18+
*.sh text=auto eol=lf
19+
/run text=auto eol=lf

.idea/deploymentchecks.http.iml

Lines changed: 6 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/php.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/phpunit.xml

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
],
1212
"require": {
1313
"php": "^8.2",
14+
"codenamephp/deploymentchecks.base": "*",
1415
"guzzlehttp/guzzle": "^7.5",
15-
"psr/http-message": "1 - 2",
1616
"psr/http-client": "^1.0",
17-
"codenamephp/deploymentchecks.base": "*"
17+
"psr/http-message": "1 - 2",
18+
"symfony/css-selector": "^6.2",
19+
"symfony/dom-crawler": "^6.2"
1820
},
1921
"minimum-stability": "dev",
2022
"prefer-stable": true,

run

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
3+
#
4+
# Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#
18+
19+
docker compose exec -it -u application application bash -c "$*"
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deploymentchecks\http\CssSelector;
19+
20+
/**
21+
* Interface to run a CSS selector and check if it exists
22+
*/
23+
interface CssSelectorInterface {
24+
25+
/**
26+
* Runs the selector and returns true if it matches at least one element, false otherwise
27+
*
28+
* @param string $selector The selector to run
29+
* @return bool True if the selector matches at least one element, false otherwise
30+
*/
31+
public function exists(string $selector) : bool;
32+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deploymentchecks\http\CssSelector\Factory\FromResponse;
19+
20+
use de\codenamephp\deploymentchecks\http\CssSelector\CssSelectorInterface;
21+
use Psr\Http\Message\ResponseInterface;
22+
23+
/**
24+
* Interface to create a CssSelectorInterface from a http response
25+
*/
26+
interface CssSelectorFromResponseInterface {
27+
28+
/**
29+
* Creates the selector from the response, e.g. by passing the body to a parser and creating the selector from that
30+
*
31+
* @param ResponseInterface $response The response to create the selector from
32+
* @return CssSelectorInterface
33+
*/
34+
public function build(ResponseInterface $response) : CssSelectorInterface;
35+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deploymentchecks\http\CssSelector\Factory\FromResponse;
19+
20+
use de\codenamephp\deploymentchecks\http\CssSelector\CssSelectorInterface;
21+
use de\codenamephp\deploymentchecks\http\CssSelector\SymfonyDomCrawlerAdapter;
22+
use Psr\Http\Message\ResponseInterface;
23+
use Symfony\Component\DomCrawler\Crawler;
24+
25+
/**
26+
* Just uses the string of the response body to create a new Crawler to pass to a new SymfonyDomCrawlerAdapter
27+
*/
28+
final class SymfonyAdapterFromResponseBody implements CssSelectorFromResponseInterface {
29+
30+
public function build(ResponseInterface $response) : CssSelectorInterface {
31+
return new SymfonyDomCrawlerAdapter(new Crawler($response->getBody()->__toString()));
32+
}
33+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* Copyright 2023 Bastian Schwarz <bastian@codename-php.de>.
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
namespace de\codenamephp\deploymentchecks\http\CssSelector;
19+
20+
use Symfony\Component\DomCrawler\Crawler;
21+
22+
/**
23+
* Adapter for the Symfony DomCrawler to run a CSS selector and check if it exists
24+
*/
25+
final readonly class SymfonyDomCrawlerAdapter implements CssSelectorInterface {
26+
27+
public function __construct(public Crawler $crawler) {}
28+
29+
public function exists(string $selector) : bool {
30+
return $this->crawler->filter($selector)->count() > 0;
31+
}
32+
}

0 commit comments

Comments
 (0)