Skip to content

Commit 9a66d8e

Browse files
Merge branch '13.2'
* 13.2: Closes #6744
2 parents 35251c8 + 073298c commit 9a66d8e

7 files changed

Lines changed: 52 additions & 42 deletions

File tree

src/Framework/Attributes/RequiresEnvironmentVariable.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,10 @@
2323
* @var non-empty-string
2424
*/
2525
private string $environmentVariableName;
26-
27-
/**
28-
* @var ?non-empty-string
29-
*/
3026
private null|string $value;
3127

3228
/**
33-
* @param non-empty-string $environmentVariableName
34-
* @param ?non-empty-string $value
29+
* @param non-empty-string $environmentVariableName
3530
*/
3631
public function __construct(string $environmentVariableName, null|string $value = null)
3732
{
@@ -47,9 +42,6 @@ public function environmentVariableName(): string
4742
return $this->environmentVariableName;
4843
}
4944

50-
/**
51-
* @return ?non-empty-string
52-
*/
5345
public function value(): null|string
5446
{
5547
return $this->value;

src/Framework/Attributes/WithEnvironmentVariable.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,10 @@
2424
*/
2525
private string $environmentVariableName;
2626

27-
/**
28-
* @var ?non-empty-string
29-
*/
3027
private null|string $value;
3128

3229
/**
33-
* @param non-empty-string $environmentVariableName
34-
* @param ?non-empty-string $value
30+
* @param non-empty-string $environmentVariableName
3531
*/
3632
public function __construct(string $environmentVariableName, null|string $value = null)
3733
{
@@ -47,9 +43,6 @@ public function environmentVariableName(): string
4743
return $this->environmentVariableName;
4844
}
4945

50-
/**
51-
* @return ?non-empty-string
52-
*/
5346
public function value(): null|string
5447
{
5548
return $this->value;

src/Metadata/Metadata.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -440,35 +440,31 @@ public static function requiresPhpunitExtensionOnMethod(string $extensionClass):
440440
}
441441

442442
/**
443-
* @param non-empty-string $environmentVariableName
444-
* @param ?non-empty-string $value
443+
* @param non-empty-string $environmentVariableName
445444
*/
446445
public static function requiresEnvironmentVariableOnClass(string $environmentVariableName, null|string $value): RequiresEnvironmentVariable
447446
{
448447
return new RequiresEnvironmentVariable(Level::CLASS_LEVEL, $environmentVariableName, $value);
449448
}
450449

451450
/**
452-
* @param non-empty-string $environmentVariableName
453-
* @param ?non-empty-string $value
451+
* @param non-empty-string $environmentVariableName
454452
*/
455453
public static function requiresEnvironmentVariableOnMethod(string $environmentVariableName, null|string $value): RequiresEnvironmentVariable
456454
{
457455
return new RequiresEnvironmentVariable(Level::METHOD_LEVEL, $environmentVariableName, $value);
458456
}
459457

460458
/**
461-
* @param non-empty-string $environmentVariableName
462-
* @param ?non-empty-string $value
459+
* @param non-empty-string $environmentVariableName
463460
*/
464461
public static function withEnvironmentVariableOnClass(string $environmentVariableName, null|string $value): WithEnvironmentVariable
465462
{
466463
return new WithEnvironmentVariable(Level::CLASS_LEVEL, $environmentVariableName, $value);
467464
}
468465

469466
/**
470-
* @param non-empty-string $environmentVariableName
471-
* @param ?non-empty-string $value
467+
* @param non-empty-string $environmentVariableName
472468
*/
473469
public static function withEnvironmentVariableOnMethod(string $environmentVariableName, null|string $value): WithEnvironmentVariable
474470
{

src/Metadata/RequiresEnvironmentVariable.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,10 @@
2020
* @var non-empty-string
2121
*/
2222
private string $environmentVariableName;
23-
24-
/**
25-
* @var ?non-empty-string
26-
*/
2723
private null|string $value;
2824

2925
/**
30-
* @param non-empty-string $environmentVariableName
31-
* @param ?non-empty-string $value
26+
* @param non-empty-string $environmentVariableName
3227
*/
3328
protected function __construct(Level $level, string $environmentVariableName, null|string $value)
3429
{
@@ -51,9 +46,6 @@ public function environmentVariableName(): string
5146
return $this->environmentVariableName;
5247
}
5348

54-
/**
55-
* @return ?non-empty-string
56-
*/
5749
public function value(): null|string
5850
{
5951
return $this->value;

src/Metadata/WithEnvironmentVariable.php

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@
2121
*/
2222
private string $environmentVariableName;
2323

24-
/**
25-
* @var ?non-empty-string
26-
*/
2724
private null|string $value;
2825

2926
/**
30-
* @param non-empty-string $environmentVariableName
31-
* @param ?non-empty-string $value
27+
* @param non-empty-string $environmentVariableName
3228
*/
3329
protected function __construct(Level $level, string $environmentVariableName, null|string $value)
3430
{
@@ -51,9 +47,6 @@ public function environmentVariableName(): string
5147
return $this->environmentVariableName;
5248
}
5349

54-
/**
55-
* @return ?non-empty-string
56-
*/
5750
public function value(): null|string
5851
{
5952
return $this->value;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
#6744: WithEnvironmentVariable supports setting an environment variable to an empty string
3+
--FILE--
4+
<?php declare(strict_types=1);
5+
$_SERVER['argv'][] = '--do-not-cache-result';
6+
$_SERVER['argv'][] = '--no-configuration';
7+
$_SERVER['argv'][] = __DIR__ . '/6744/Issue6744Test.php';
8+
9+
require_once __DIR__ . '/../../bootstrap.php';
10+
(new PHPUnit\TextUI\Application)->run($_SERVER['argv']);
11+
--EXPECTF--
12+
PHPUnit %s by Sebastian Bergmann and contributors.
13+
14+
Runtime: %s
15+
16+
. 1 / 1 (100%)
17+
18+
Time: %s, Memory: %s
19+
20+
OK (1 test, 2 assertions)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types=1);
2+
/*
3+
* This file is part of PHPUnit.
4+
*
5+
* (c) Sebastian Bergmann <sebastian@phpunit.de>
6+
*
7+
* For the full copyright and license information, please view the LICENSE
8+
* file that was distributed with this source code.
9+
*/
10+
namespace PHPUnit\TestFixture;
11+
12+
use function getenv;
13+
use PHPUnit\Framework\Attributes\WithEnvironmentVariable;
14+
use PHPUnit\Framework\TestCase;
15+
16+
final class Issue6744Test extends TestCase
17+
{
18+
#[WithEnvironmentVariable('FOO', '')]
19+
public function testEnvironmentVariableCanBeSetToEmptyString(): void
20+
{
21+
$this->assertSame('', $_ENV['FOO']);
22+
$this->assertSame('', getenv('FOO'));
23+
}
24+
}

0 commit comments

Comments
 (0)