Browse Source

Merge pull request #17207 from cakephp/5.x-assert

Make assertion requirement for testing env more explicit.
Mark Story 2 years ago
parent
commit
f104f2da80
3 changed files with 25 additions and 0 deletions
  1. 1 0
      phpunit.xml.dist
  2. 1 0
      tests/bootstrap.php
  3. 23 0
      tests/check.php

+ 1 - 0
phpunit.xml.dist

@@ -58,6 +58,7 @@
         <env name="DB_URL" value="sqlserver://localhost/cake_test?timezone=UTC"/>
         -->
 
+        <const name="PHPUNIT_TESTSUITE" value="true"/>
         <!-- Constants used by Http Interop's Http Factory tests -->
         <const name="REQUEST_FACTORY" value="Cake\Http\RequestFactory"/>
         <const name="RESPONSE_FACTORY" value="Cake\Http\ResponseFactory"/>

+ 1 - 0
tests/bootstrap.php

@@ -62,6 +62,7 @@ define('CONFIG', TEST_APP . 'config' . DS);
 @mkdir(CACHE . 'models');
 // phpcs:enable
 
+require_once 'check.php';
 require_once CORE_PATH . 'config/bootstrap.php';
 
 date_default_timezone_set('UTC');

+ 23 - 0
tests/check.php

@@ -0,0 +1,23 @@
+<?php
+declare(strict_types=1);
+
+/**
+ * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
+ * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
+ *
+ * Licensed under The MIT License
+ * Redistributions of files must retain the above copyright notice.
+ *
+ * @copyright     Cake Software Foundation, Inc. (https://cakefoundation.org)
+ * @link          https://cakephp.org CakePHP(tm) Project
+ * @license       https://opensource.org/licenses/mit-license.php MIT License
+ */
+
+if (!defined('PHPUNIT_TESTSUITE') || !PHPUNIT_TESTSUITE) {
+    return;
+}
+
+$assertions = (int)ini_get('zend.assertions');
+if ($assertions !== 1) {
+    throw new RuntimeException('Assertions are not activated, but needed for tests to run. Please set respective directives in your php.ini (`zend.assertions = 1`).');
+}