Skip to content
This repository has been archived by the owner on Jan 1, 2023. It is now read-only.

Commit

Permalink
Split the resources test in multiple ones
Browse files Browse the repository at this point in the history
To ease debugging
  • Loading branch information
nesk committed Oct 31, 2020
1 parent 5636bbf commit e201ee8
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions tests/PuphpeteerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,56 +103,57 @@ public function can_intercept_requests()

/**
* @test
* @dataProvider resourceProvider
* @dontPopulateProperties browser
*/
public function check_all_resources_are_supported()
public function check_all_resources_are_supported(string $name)
{
$incompleteResources = [];
$incompleteTest = false;
$resourceInstantiator = new ResourceInstantiator($this->browserOptions, $this->url);
$resource = $resourceInstantiator->{$name}(new Puppeteer, $this->browserOptions);

foreach ($resourceInstantiator->getResourceNames() as $name) {
$resource = $resourceInstantiator->{$name}(new Puppeteer, $this->browserOptions);

if ($resource instanceof UntestableResource) {
$incompleteResources[$name] = $resource;
} else if ($resource instanceof RiskyResource) {
if (!empty($resource->exception())) {
$incompleteResources[$name] = $resource;
} else {
try {
$this->assertInstanceOf("Nesk\\Puphpeteer\\Resources\\$name", $resource->value());
} catch (ExpectationFailedException $exception) {
$incompleteResources[$name] = $resource;
}
}
if ($resource instanceof UntestableResource) {
$incompleteTest = true;
} else if ($resource instanceof RiskyResource) {
if (!empty($resource->exception())) {
$incompleteTest = true;
} else {
$this->assertInstanceOf("Nesk\\Puphpeteer\\Resources\\$name", $resource);
try {
$this->assertInstanceOf("Nesk\\Puphpeteer\\Resources\\$name", $resource->value());
} catch (ExpectationFailedException $exception) {
$incompleteTest = true;
}
}
} else {
$this->assertInstanceOf("Nesk\\Puphpeteer\\Resources\\$name", $resource);
}

if (empty($incompleteResources)) return;
if (!$incompleteTest) return;

$incompleteText = "The following resources have not been tested properly, probably"
." for good reasons but you might want to have a look:\n";
$reason = "The \"$name\" resource has not been tested properly, probably"
." for a good reason but you might want to have a look: \n\n ";

foreach ($incompleteResources as $name => $resource) {
if ($resource instanceof UntestableResource) {
$reason = "Marked as untestable";
} else if ($resource instanceof RiskyResource) {
if (!empty($exception = $resource->exception())) {
$reason = "Marked as risky because of a Node error: {$exception->getMessage()}";
} else {
$value = print_r($resource->value(), true);
$reason = "Marked as risky because of an unexpected value: $value";
}
if ($resource instanceof UntestableResource) {
$reason .= "\e[33mMarked as untestable.\e[0m";
} else {
if (!empty($exception = $resource->exception())) {
$reason .= "\e[31mMarked as risky because of a Node error: {$exception->getMessage()}\e[0m";
} else {
$reason = "Unknow reason";
$value = print_r($resource->value(), true);
$reason .= "\e[31mMarked as risky because of an unexpected value: $value\e[0m";
}

$incompleteText .= "\n$name - $reason";
}

$this->markTestIncomplete($incompleteText);
$this->markTestIncomplete($reason);
}

public function resourceProvider(): \Generator
{
$resourceNames = (new ResourceInstantiator([], ''))->getResourceNames();

foreach ($resourceNames as $name) {
yield [$name];
}
}

/**
Expand Down

0 comments on commit e201ee8

Please sign in to comment.