Skip to content

Commit 1602441

Browse files
Tobias Weichartnicolas-grekas
authored andcommitted
[PhpUnitBridge] added polyfill for assertStringContainsString*()
1 parent 42a4de0 commit 1602441

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/ForwardCompatTestTraitForV5.php

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bridge\PhpUnit\Legacy;
1313

14+
use PHPUnit\Framework\Constraint\StringContains;
1415
use PHPUnit\Framework\MockObject\MockObject;
1516
use PHPUnit\Framework\TestCase;
1617

@@ -51,33 +52,21 @@ protected function tearDown()
5152
self::doTearDown();
5253
}
5354

54-
/**
55-
* @return void
56-
*/
5755
private static function doSetUpBeforeClass()
5856
{
5957
parent::setUpBeforeClass();
6058
}
6159

62-
/**
63-
* @return void
64-
*/
6560
private static function doTearDownAfterClass()
6661
{
6762
parent::tearDownAfterClass();
6863
}
6964

70-
/**
71-
* @return void
72-
*/
7365
private function doSetUp()
7466
{
7567
parent::setUp();
7668
}
7769

78-
/**
79-
* @return void
80-
*/
8170
private function doTearDown()
8271
{
8372
parent::tearDown();
@@ -233,6 +222,32 @@ public static function assertIsIterable($actual, $message = '')
233222
static::assertInternalType('iterable', $actual, $message);
234223
}
235224

225+
/**
226+
* @param string $needle
227+
* @param string $haystack
228+
* @param string $message
229+
*
230+
* @return void
231+
*/
232+
public static function assertStringContainsString($needle, $haystack, $message = '')
233+
{
234+
$constraint = new StringContains($needle, false);
235+
static::assertThat($haystack, $constraint, $message);
236+
}
237+
238+
/**
239+
* @param string $needle
240+
* @param string $haystack
241+
* @param string $message
242+
*
243+
* @return void
244+
*/
245+
public static function assertStringContainsStringIgnoringCase($needle, $haystack, $message = '')
246+
{
247+
$constraint = new StringContains($needle, true);
248+
static::assertThat($haystack, $constraint, $message);
249+
}
250+
236251
/**
237252
* @param string $message
238253
*
@@ -303,6 +318,8 @@ public function expectException($exception)
303318
}
304319

305320
/**
321+
* @param int|string $code
322+
*
306323
* @return void
307324
*/
308325
public function expectExceptionCode($code)
@@ -315,7 +332,7 @@ public function expectExceptionCode($code)
315332

316333
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionCode');
317334
$property->setAccessible(true);
318-
$property->setValue($this, $exception);
335+
$property->setValue($this, $code);
319336
}
320337

321338
/**
@@ -333,7 +350,7 @@ public function expectExceptionMessage($message)
333350

334351
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessage');
335352
$property->setAccessible(true);
336-
$property->setValue($this, $exception);
353+
$property->setValue($this, $message);
337354
}
338355

339356
/**
@@ -351,6 +368,6 @@ public function expectExceptionMessageRegExp($messageRegExp)
351368

352369
$property = new \ReflectionProperty(class_exists('PHPUnit_Framework_TestCase') ? 'PHPUnit_Framework_TestCase' : TestCase::class, 'expectedExceptionMessageRegExp');
353370
$property->setAccessible(true);
354-
$property->setValue($this, $exception);
371+
$property->setValue($this, $messageRegExp);
355372
}
356373
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy