Skip to content

Commit

Permalink
Fixed test and added support for php8 in composer.
Browse files Browse the repository at this point in the history
  • Loading branch information
Teye Heimans committed Nov 3, 2021
1 parent 1da1cf9 commit 8140b49
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 85 deletions.
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,16 @@
"require": {
"ext-json": "*",
"guzzlehttp/guzzle": "^6.3|^7.0",
"php": "~7.1",
"php": "~7.1|^8.0",
"symfony/filesystem": ">=2.3",
"symfony/process": ">=3.3",
"wrench/wrench": "~2.0.10"
},
"require-dev": {
"jakub-onderka/php-parallel-lint": "~1.0.0",
"nette/php-generator": "~2.1|~3.0",
"phpstan/phpstan": "^0.11.4",
"phpunit/phpunit": "~6.4"
"phpstan/phpstan": "^0.12.99",
"phpunit/phpunit": "^9.5"
},
"autoload": {
"psr-4": {
Expand Down
27 changes: 11 additions & 16 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,18 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.4/phpunit.xsd">

<filter>
<whitelist addUncoveredFilesFromWhitelist="true" processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src</directory>
</whitelist>
</filter>

<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">test</directory>
</testsuite>
</testsuites>

<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true" processUncoveredFiles="true">
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Tests">
<directory suffix="Test.php">test</directory>
</testsuite>
</testsuites>
</phpunit>
140 changes: 74 additions & 66 deletions test/ChromeDevtoolsProtocol/DevtoolsClientTest.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

namespace ChromeDevtoolsProtocol;

use ChromeDevtoolsProtocol\Exception\ErrorException;
Expand All @@ -13,77 +14,84 @@

class DevtoolsClientTest extends TestCase
{
/**
* @throws \Exception
*/
public function testHandleCertificateError()
{
$ctx = Context::withTimeout(Context::background(), 10);
$launcher = new Launcher();
$instance = $launcher->launch($ctx);
try {
$tabs = $instance->tabs($ctx);
$this->assertEquals(1, sizeof($tabs));
if (sizeof($tabs) != 1) {
throw new \Exception('Failed to retrieve tab!');
}
$tab = $tabs[0];

public function testHandleCertificateError()
{
$ctx = Context::withTimeout(Context::background(), 10);
$launcher = new Launcher();
$instance = $launcher->launch($ctx);
try {
$tab = $instance->tabs($ctx)[0];

$client = $tab->devtools();
try {
$client->page()->enable($ctx);
$client->network()->enable($ctx, EnableRequest::make());
$client->security()->enable($ctx);
$client->security()->setOverrideCertificateErrors(
$ctx,
SetOverrideCertificateErrorsRequest::builder()
->setOverride(true)
->build()
);
$client->security()->addCertificateErrorListener(function (CertificateErrorEvent $ev) use ($ctx, $client) {
$client->security()->handleCertificateError(
$ctx,
HandleCertificateErrorRequest::builder()
->setEventId($ev->eventId)
->setAction(CertificateErrorActionEnum::CONTINUE)
->build()
);
});
$client->page()->navigate($ctx, NavigateRequest::builder()->setUrl("https://untrusted-root.badssl.com/")->build());
$client->page()->awaitLoadEventFired($ctx);

$this->assertTrue(true, "Ok, handling certificate errors works");

} finally {
$client->close();
}

} finally {
$instance->close();
}
}

public function testErrorHandling()
{
$this->expectException(ErrorException::class);
$client = $tab->devtools();
try {
$client->page()->enable($ctx);
$client->network()->enable($ctx, EnableRequest::make());
$client->security()->enable($ctx);
$client->security()->setOverrideCertificateErrors(
$ctx,
SetOverrideCertificateErrorsRequest::builder()
->setOverride(true)
->build()
);
$client->security()->addCertificateErrorListener(function (CertificateErrorEvent $ev) use (
$ctx,
$client
) {
$client->security()->handleCertificateError(
$ctx,
HandleCertificateErrorRequest::builder()
->setEventId($ev->eventId)
->setAction(CertificateErrorActionEnum::CONTINUE)
->build()
);
});
$client->page()->navigate($ctx,
NavigateRequest::builder()->setUrl("https://untrusted-root.badssl.com/")->build());
$client->page()->awaitLoadEventFired($ctx);

$ctx = Context::withTimeout(Context::background(), 10);
$launcher = new Launcher();
$instance = $launcher->launch($ctx);
try {
$tabs = $instance->tabs($ctx);
foreach ($tabs as $tab) {
$tab->close($ctx);
}
$this->assertTrue(true, "Ok, handling certificate errors works");
} finally {
$client->close();
}
} finally {
$instance->close();
}
}

$tab = $instance->open($ctx);
$this->assertEquals("about:blank", $tab->url);
public function testErrorHandling()
{
$this->expectException(ErrorException::class);

/** @var DevtoolsClientInterface & InternalClientInterface $client */
$client = $tab->devtools();
try {
$ctx = Context::withTimeout(Context::background(), 10);
$launcher = new Launcher();
$instance = $launcher->launch($ctx);
try {
$tabs = $instance->tabs($ctx);
foreach ($tabs as $tab) {
$tab->close($ctx);
}

$client->executeCommand($ctx, "SomeCommand.thatDoesNotExist", new \stdClass());
$tab = $instance->open($ctx);
$this->assertEquals("about:blank", $tab->url);

} finally {
$client->close();
}
} finally {
$instance->close();
}
}
/** @var DevtoolsClientInterface & InternalClientInterface $client */
$client = $tab->devtools();
try {

$client->executeCommand($ctx, "SomeCommand.thatDoesNotExist", new \stdClass());
} finally {
$client->close();
}
} finally {
$instance->close();
}
}
}

0 comments on commit 8140b49

Please sign in to comment.