Skip to content

Commit

Permalink
Add test for header overrides
Browse files Browse the repository at this point in the history
  • Loading branch information
shalvah committed Jun 17, 2024
1 parent b856570 commit a1cb38e
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions tests/Unit/ExtractorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,47 @@ public function invokes_strategy_based_on_new_strategy_configs()
$this->assertNotEmpty($parsed->responses);
}

/** @test */
public function adds_override_for_headers_based_on_deprecated_route_apply_rules()
{
$config = $this->config;
$config['strategies']['headers'] = [Strategies\Headers\GetFromRouteRules::class];

$extractor = $this->makeExtractor($config);
$route = $this->createRoute('GET', '/get', 'dummy');
$parsed = $extractor->processRoute($route, ['headers' => ['content-type' => 'application/json+vnd']]);
$this->assertArraySubset($parsed->headers, ['content-type' => 'application/json+vnd']);

$parsed = $extractor->processRoute($route);
$this->assertEmpty($parsed->headers);
}

/** @test */
public function adds_override_for_headers_based_on_strategy_configs()
{
$route = $this->createRoute('GET', '/get', 'dummy');
$config = $this->config;

$config['strategies']['headers'] = [Strategies\Headers\GetFromHeaderAttribute::class];
$extractor = $this->makeExtractor($config);
$parsed = $extractor->processRoute($route);
$this->assertEmpty($parsed->headers);

$headers = [
'accept' => 'application/json',
'Content-Type' => 'application/json+vnd',
];
$config['strategies']['headers'] = [
Strategies\Headers\GetFromHeaderAttribute::class,
[
'override', $headers
],
];
$extractor = $this->makeExtractor($config);
$parsed = $extractor->processRoute($route);
$this->assertArraySubset($parsed->headers, $headers);
}

/**
* @test
* @dataProvider authRules
Expand Down

0 comments on commit a1cb38e

Please sign in to comment.