TestCase.php 7.17 KB
Newer Older
Ketan's avatar
Ketan committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
<?php

namespace Codeception\PHPUnit;


use PHPUnit\Framework\AssertionFailedError;

abstract class TestCase extends \PHPUnit\Framework\TestCase
{

    protected function setUp()
    {
        if (method_exists($this, '_setUp')) {
            $this->_setUp();
        }
    }

    protected function tearDown()
    {
        if (method_exists($this, '_tearDown')) {
            $this->_tearDown();
        }
    }

    public static function setUpBeforeClass()
    {
        if (method_exists(get_called_class(), '_setUpBeforeClass')) {
            static::_setUpBeforeClass();
        }
    }

    public static function tearDownAfterClass()
    {
        if (method_exists(get_called_class(), '_tearDownAfterClass')) {
            static::_tearDownAfterClass();
        }
    }

    public static function assertStringContainsString($needle, $haystack, $message = '')
    {
        if (!is_string($needle)) {
            throw new AssertionFailedError('Needle is not string');
        }
        if (!is_string($haystack)) {
            throw new AssertionFailedError('Haystack is not string');
        }
        \Codeception\PHPUnit\TestCase::assertContains($needle, $haystack, $message);
    }

    public static function assertStringNotContainsString($needle, $haystack, $message = '')
    {

        if (!is_string($needle)) {
            throw new AssertionFailedError('Needle is not string');
        }
        if (!is_string($haystack)) {
            throw new AssertionFailedError('Haystack is not string');
        }
        \Codeception\PHPUnit\TestCase::assertNotContains($needle, $haystack, $message);
    }

    public static function assertStringContainsStringIgnoringCase($needle, $haystack, $message = '')
    {
        if (!is_string($needle)) {
            throw new AssertionFailedError('Needle is not string');
        }
        if (!is_string($haystack)) {
            throw new AssertionFailedError('Haystack is not string');
        }
        \Codeception\PHPUnit\TestCase::assertContains($needle, $haystack, $message, true);
    }

    public static function assertStringNotContainsStringIgnoringCase($needle, $haystack, $message = '')
    {

        if (!is_string($needle)) {
            throw new AssertionFailedError('Needle is not string');
        }
        if (!is_string($haystack)) {
            throw new AssertionFailedError('Haystack is not string');
        }
        \Codeception\PHPUnit\TestCase::assertNotContains($needle, $haystack, $message, true);
    }

    public static function assertIsArray($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('array', $actual, $message);
    }

    public static function assertIsBool($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('bool', $actual, $message);
    }

    public static function assertIsFloat($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('float', $actual, $message);
    }

    public static function assertIsInt($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('int', $actual, $message);
    }

    public static function assertIsNumeric($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('numeric', $actual, $message);
    }

    public static function assertIsObject($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('object', $actual, $message);
    }

    public static function assertIsResource($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('resource', $actual, $message);
    }

    public static function assertIsString($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('string', $actual, $message);
    }

    public static function assertIsScalar($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('scalar', $actual, $message);
    }

    public static function assertIsCallable($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertInternalType('callable', $actual, $message);
    }

    public static function assertIsNotArray($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('array', $actual, $message);
    }

    public static function assertIsNotBool($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('bool', $actual, $message);
    }

    public static function assertIsNotFloat($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('float', $actual, $message);
    }

    public static function assertIsNotInt($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('int', $actual, $message);
    }

    public static function assertIsNotNumeric($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('numeric', $actual, $message);
    }

    public static function assertIsNotObject($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('object', $actual, $message);
    }

    public static function assertIsNotResource($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('resource', $actual, $message);
    }

    public static function assertIsNotString($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('string', $actual, $message);
    }

    public static function assertIsNotScalar($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('scalar', $actual, $message);
    }

    public static function assertIsNotCallable($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('callable', $actual, $message);
    }

    public static function assertIsNotIterable($actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotInternalType('iterable', $actual, $message);
    }

    public static function assertEqualsCanonicalizing($expected, $actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertEquals($expected, $actual, $message, 0.0, 10, true, false);
    }

    public static function assertNotEqualsCanonicalizing($expected, $actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotEquals($expected, $actual, $message, 0.0, 10, true, false);
    }

    public static function assertEqualsIgnoringCase($expected, $actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertEquals($expected, $actual, $message, 0.0, 10, false, true);
    }

    public static function assertNotEqualsIgnoringCase($expected, $actual, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotEquals($expected, $actual, $message, 0.0, 10, false, true);
    }

    public static function assertEqualsWithDelta($expected, $actual, $delta, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertEquals($expected, $actual, $message, $delta, 10, false, false);
    }

    public static function assertNotEqualsWithDelta($expected, $actual, $delta, $message = '')
    {
        \Codeception\PHPUnit\TestCase::assertNotEquals($expected, $actual, $message, $delta, 10, false, false);
    }
}