diff --git a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php index 541258a..fcb5577 100644 --- a/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php +++ b/core/modules/system/src/Tests/Cache/ApcuBackendUnitTest.php @@ -43,10 +43,35 @@ protected function getRequirements() { return $requirements; } + /** + * Check if requirements fail. + * + * If the requirements fail the test method should return immediately instead + * of running any tests. Messages will be output to display why the test was + * skipped. + */ + protected function requirementsFail() { + $requirements = $this->getRequirements(); + if (!empty($requirements)) { + foreach ($requirements as $message) { + $this->pass($message); + } + return TRUE; + } + + return FALSE; + } + + /** + * {@inheritdoc} + */ protected function createCacheBackend($bin) { return new ApcuBackend($bin, $this->databasePrefix, \Drupal::service('cache_tags.invalidator.checksum')); } + /** + * {@inheritdoc} + */ protected function tearDown() { foreach ($this->cachebackends as $bin => $cachebackend) { $this->cachebackends[$bin]->removeBin(); @@ -58,10 +83,7 @@ protected function tearDown() { * {@inheritdoc} */ public function testSetGet() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testSetGet(); @@ -71,10 +93,7 @@ public function testSetGet() { * {@inheritdoc} */ public function testDelete() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testDelete(); @@ -84,10 +103,7 @@ public function testDelete() { * {@inheritdoc} */ public function testValueTypeIsKept() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testValueTypeIsKept(); @@ -97,10 +113,7 @@ public function testValueTypeIsKept() { * {@inheritdoc} */ public function testGetMultiple() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testGetMultiple(); @@ -110,10 +123,7 @@ public function testGetMultiple() { * {@inheritdoc} */ public function testSetMultiple() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testSetMultiple(); @@ -123,10 +133,7 @@ public function testSetMultiple() { * {@inheritdoc} */ public function testDeleteMultiple() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testDeleteMultiple(); @@ -136,10 +143,7 @@ public function testDeleteMultiple() { * {@inheritdoc} */ public function testDeleteAll() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testDeleteAll(); @@ -149,10 +153,7 @@ public function testDeleteAll() { * {@inheritdoc} */ public function testInvalidate() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testInvalidate(); @@ -162,10 +163,7 @@ public function testInvalidate() { * {@inheritdoc} */ public function testInvalidateTags() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testInvalidateTags(); @@ -175,10 +173,7 @@ public function testInvalidateTags() { * {@inheritdoc} */ public function testInvalidateAll() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testInvalidateAll(); @@ -188,10 +183,7 @@ public function testInvalidateAll() { * {@inheritdoc} */ public function testRemoveBin() { - if (!empty($this->getRequirements())) { - foreach ($this->getRequirements() as $message) { - $this->pass($message); - } + if ($this->requirementsFail()) { return; } parent::testRemoveBin();