PageRenderTime 83ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/phpunit/phpunit/src/Framework/Assert.php

https://gitlab.com/jhonn/rest
PHP | 3087 lines | 1420 code | 320 blank | 1347 comment | 126 complexity | 1b099eeb6481e5b66a36e24ef5dae0ad MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * PHPUnit
  4. *
  5. * Copyright (c) 2001-2014, Sebastian Bergmann <sebastian@phpunit.de>.
  6. * All rights reserved.
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. *
  12. * * Redistributions of source code must retain the above copyright
  13. * notice, this list of conditions and the following disclaimer.
  14. *
  15. * * Redistributions in binary form must reproduce the above copyright
  16. * notice, this list of conditions and the following disclaimer in
  17. * the documentation and/or other materials provided with the
  18. * distribution.
  19. *
  20. * * Neither the name of Sebastian Bergmann nor the names of his
  21. * contributors may be used to endorse or promote products derived
  22. * from this software without specific prior written permission.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  29. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  30. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  31. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  32. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  33. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  34. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  35. * POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * @package PHPUnit
  38. * @subpackage Framework
  39. * @author Sebastian Bergmann <sebastian@phpunit.de>
  40. * @copyright 2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
  41. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  42. * @link http://www.phpunit.de/
  43. * @since File available since Release 2.0.0
  44. */
  45. /**
  46. * A set of assert methods.
  47. *
  48. * @package PHPUnit
  49. * @subpackage Framework
  50. * @author Sebastian Bergmann <sebastian@phpunit.de>
  51. * @copyright 2001-2014 Sebastian Bergmann <sebastian@phpunit.de>
  52. * @license http://www.opensource.org/licenses/BSD-3-Clause The BSD 3-Clause License
  53. * @link http://www.phpunit.de/
  54. * @since Class available since Release 2.0.0
  55. */
  56. abstract class PHPUnit_Framework_Assert
  57. {
  58. /**
  59. * @var integer
  60. */
  61. private static $count = 0;
  62. /**
  63. * Asserts that an array has a specified key.
  64. *
  65. * @param mixed $key
  66. * @param array|ArrayAccess $array
  67. * @param string $message
  68. * @since Method available since Release 3.0.0
  69. */
  70. public static function assertArrayHasKey($key, $array, $message = '')
  71. {
  72. if (!(is_integer($key) || is_string($key))) {
  73. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  74. 1,
  75. 'integer or string'
  76. );
  77. }
  78. if (!(is_array($array) || $array instanceof ArrayAccess)) {
  79. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  80. 2,
  81. 'array or ArrayAccess'
  82. );
  83. }
  84. $constraint = new PHPUnit_Framework_Constraint_ArrayHasKey($key);
  85. self::assertThat($array, $constraint, $message);
  86. }
  87. /**
  88. * Asserts that an array has a specified subset.
  89. *
  90. * @param array|ArrayAccess $subset
  91. * @param array|ArrayAccess $array
  92. * @param boolean $strict Check for object identity
  93. * @param string $message
  94. * @since Method available since Release 4.4.0
  95. */
  96. public static function assertArraySubset($subset, $array, $strict = false, $message = '')
  97. {
  98. if (!is_array($subset)) {
  99. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  100. 1, 'array or ArrayAccess'
  101. );
  102. }
  103. if (!is_array($array)) {
  104. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  105. 2, 'array or ArrayAccess'
  106. );
  107. }
  108. $constraint = new PHPUnit_Framework_Constraint_ArraySubset($subset, $strict);
  109. self::assertThat($array, $constraint, $message);
  110. }
  111. /**
  112. * Asserts that an array does not have a specified key.
  113. *
  114. * @param mixed $key
  115. * @param array|ArrayAccess $array
  116. * @param string $message
  117. * @since Method available since Release 3.0.0
  118. */
  119. public static function assertArrayNotHasKey($key, $array, $message = '')
  120. {
  121. if (!(is_integer($key) || is_string($key))) {
  122. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  123. 1,
  124. 'integer or string'
  125. );
  126. }
  127. if (!(is_array($array) || $array instanceof ArrayAccess)) {
  128. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  129. 2,
  130. 'array or ArrayAccess'
  131. );
  132. }
  133. $constraint = new PHPUnit_Framework_Constraint_Not(
  134. new PHPUnit_Framework_Constraint_ArrayHasKey($key)
  135. );
  136. self::assertThat($array, $constraint, $message);
  137. }
  138. /**
  139. * Asserts that a haystack contains a needle.
  140. *
  141. * @param mixed $needle
  142. * @param mixed $haystack
  143. * @param string $message
  144. * @param boolean $ignoreCase
  145. * @param boolean $checkForObjectIdentity
  146. * @param boolean $checkForNonObjectIdentity
  147. * @since Method available since Release 2.1.0
  148. */
  149. public static function assertContains($needle, $haystack, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
  150. {
  151. if (is_array($haystack) ||
  152. is_object($haystack) && $haystack instanceof Traversable) {
  153. $constraint = new PHPUnit_Framework_Constraint_TraversableContains(
  154. $needle,
  155. $checkForObjectIdentity,
  156. $checkForNonObjectIdentity
  157. );
  158. } elseif (is_string($haystack)) {
  159. $constraint = new PHPUnit_Framework_Constraint_StringContains(
  160. $needle,
  161. $ignoreCase
  162. );
  163. } else {
  164. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  165. 2,
  166. 'array, traversable or string'
  167. );
  168. }
  169. self::assertThat($haystack, $constraint, $message);
  170. }
  171. /**
  172. * Asserts that a haystack that is stored in a static attribute of a class
  173. * or an attribute of an object contains a needle.
  174. *
  175. * @param mixed $needle
  176. * @param string $haystackAttributeName
  177. * @param mixed $haystackClassOrObject
  178. * @param string $message
  179. * @param boolean $ignoreCase
  180. * @param boolean $checkForObjectIdentity
  181. * @param boolean $checkForNonObjectIdentity
  182. * @since Method available since Release 3.0.0
  183. */
  184. public static function assertAttributeContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
  185. {
  186. self::assertContains(
  187. $needle,
  188. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  189. $message,
  190. $ignoreCase,
  191. $checkForObjectIdentity,
  192. $checkForNonObjectIdentity
  193. );
  194. }
  195. /**
  196. * Asserts that a haystack does not contain a needle.
  197. *
  198. * @param mixed $needle
  199. * @param mixed $haystack
  200. * @param string $message
  201. * @param boolean $ignoreCase
  202. * @param boolean $checkForObjectIdentity
  203. * @param boolean $checkForNonObjectIdentity
  204. * @since Method available since Release 2.1.0
  205. */
  206. public static function assertNotContains($needle, $haystack, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
  207. {
  208. if (is_array($haystack) ||
  209. is_object($haystack) && $haystack instanceof Traversable) {
  210. $constraint = new PHPUnit_Framework_Constraint_Not(
  211. new PHPUnit_Framework_Constraint_TraversableContains(
  212. $needle,
  213. $checkForObjectIdentity,
  214. $checkForNonObjectIdentity
  215. )
  216. );
  217. } elseif (is_string($haystack)) {
  218. $constraint = new PHPUnit_Framework_Constraint_Not(
  219. new PHPUnit_Framework_Constraint_StringContains(
  220. $needle,
  221. $ignoreCase
  222. )
  223. );
  224. } else {
  225. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  226. 2,
  227. 'array, traversable or string'
  228. );
  229. }
  230. self::assertThat($haystack, $constraint, $message);
  231. }
  232. /**
  233. * Asserts that a haystack that is stored in a static attribute of a class
  234. * or an attribute of an object does not contain a needle.
  235. *
  236. * @param mixed $needle
  237. * @param string $haystackAttributeName
  238. * @param mixed $haystackClassOrObject
  239. * @param string $message
  240. * @param boolean $ignoreCase
  241. * @param boolean $checkForObjectIdentity
  242. * @param boolean $checkForNonObjectIdentity
  243. * @since Method available since Release 3.0.0
  244. */
  245. public static function assertAttributeNotContains($needle, $haystackAttributeName, $haystackClassOrObject, $message = '', $ignoreCase = false, $checkForObjectIdentity = true, $checkForNonObjectIdentity = false)
  246. {
  247. self::assertNotContains(
  248. $needle,
  249. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  250. $message,
  251. $ignoreCase,
  252. $checkForObjectIdentity,
  253. $checkForNonObjectIdentity
  254. );
  255. }
  256. /**
  257. * Asserts that a haystack contains only values of a given type.
  258. *
  259. * @param string $type
  260. * @param mixed $haystack
  261. * @param boolean $isNativeType
  262. * @param string $message
  263. * @since Method available since Release 3.1.4
  264. */
  265. public static function assertContainsOnly($type, $haystack, $isNativeType = null, $message = '')
  266. {
  267. if (!(is_array($haystack) ||
  268. is_object($haystack) && $haystack instanceof Traversable)) {
  269. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  270. 2,
  271. 'array or traversable'
  272. );
  273. }
  274. if ($isNativeType == null) {
  275. $isNativeType = PHPUnit_Util_Type::isType($type);
  276. }
  277. self::assertThat(
  278. $haystack,
  279. new PHPUnit_Framework_Constraint_TraversableContainsOnly(
  280. $type,
  281. $isNativeType
  282. ),
  283. $message
  284. );
  285. }
  286. /**
  287. * Asserts that a haystack contains only instances of a given classname
  288. *
  289. * @param string $classname
  290. * @param array|Traversable $haystack
  291. * @param string $message
  292. */
  293. public static function assertContainsOnlyInstancesOf($classname, $haystack, $message = '')
  294. {
  295. if (!(is_array($haystack) ||
  296. is_object($haystack) && $haystack instanceof Traversable)) {
  297. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  298. 2,
  299. 'array or traversable'
  300. );
  301. }
  302. self::assertThat(
  303. $haystack,
  304. new PHPUnit_Framework_Constraint_TraversableContainsOnly(
  305. $classname,
  306. false
  307. ),
  308. $message
  309. );
  310. }
  311. /**
  312. * Asserts that a haystack that is stored in a static attribute of a class
  313. * or an attribute of an object contains only values of a given type.
  314. *
  315. * @param string $type
  316. * @param string $haystackAttributeName
  317. * @param mixed $haystackClassOrObject
  318. * @param boolean $isNativeType
  319. * @param string $message
  320. * @since Method available since Release 3.1.4
  321. */
  322. public static function assertAttributeContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = null, $message = '')
  323. {
  324. self::assertContainsOnly(
  325. $type,
  326. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  327. $isNativeType,
  328. $message
  329. );
  330. }
  331. /**
  332. * Asserts that a haystack does not contain only values of a given type.
  333. *
  334. * @param string $type
  335. * @param mixed $haystack
  336. * @param boolean $isNativeType
  337. * @param string $message
  338. * @since Method available since Release 3.1.4
  339. */
  340. public static function assertNotContainsOnly($type, $haystack, $isNativeType = null, $message = '')
  341. {
  342. if (!(is_array($haystack) ||
  343. is_object($haystack) && $haystack instanceof Traversable)) {
  344. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  345. 2,
  346. 'array or traversable'
  347. );
  348. }
  349. if ($isNativeType == null) {
  350. $isNativeType = PHPUnit_Util_Type::isType($type);
  351. }
  352. self::assertThat(
  353. $haystack,
  354. new PHPUnit_Framework_Constraint_Not(
  355. new PHPUnit_Framework_Constraint_TraversableContainsOnly(
  356. $type,
  357. $isNativeType
  358. )
  359. ),
  360. $message
  361. );
  362. }
  363. /**
  364. * Asserts that a haystack that is stored in a static attribute of a class
  365. * or an attribute of an object does not contain only values of a given
  366. * type.
  367. *
  368. * @param string $type
  369. * @param string $haystackAttributeName
  370. * @param mixed $haystackClassOrObject
  371. * @param boolean $isNativeType
  372. * @param string $message
  373. * @since Method available since Release 3.1.4
  374. */
  375. public static function assertAttributeNotContainsOnly($type, $haystackAttributeName, $haystackClassOrObject, $isNativeType = null, $message = '')
  376. {
  377. self::assertNotContainsOnly(
  378. $type,
  379. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  380. $isNativeType,
  381. $message
  382. );
  383. }
  384. /**
  385. * Asserts the number of elements of an array, Countable or Traversable.
  386. *
  387. * @param integer $expectedCount
  388. * @param mixed $haystack
  389. * @param string $message
  390. */
  391. public static function assertCount($expectedCount, $haystack, $message = '')
  392. {
  393. if (!is_int($expectedCount)) {
  394. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
  395. }
  396. if (!$haystack instanceof Countable &&
  397. !$haystack instanceof Traversable &&
  398. !is_array($haystack)) {
  399. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'countable or traversable');
  400. }
  401. self::assertThat(
  402. $haystack,
  403. new PHPUnit_Framework_Constraint_Count($expectedCount),
  404. $message
  405. );
  406. }
  407. /**
  408. * Asserts the number of elements of an array, Countable or Traversable
  409. * that is stored in an attribute.
  410. *
  411. * @param integer $expectedCount
  412. * @param string $haystackAttributeName
  413. * @param mixed $haystackClassOrObject
  414. * @param string $message
  415. * @since Method available since Release 3.6.0
  416. */
  417. public static function assertAttributeCount($expectedCount, $haystackAttributeName, $haystackClassOrObject, $message = '')
  418. {
  419. self::assertCount(
  420. $expectedCount,
  421. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  422. $message
  423. );
  424. }
  425. /**
  426. * Asserts the number of elements of an array, Countable or Traversable.
  427. *
  428. * @param integer $expectedCount
  429. * @param mixed $haystack
  430. * @param string $message
  431. */
  432. public static function assertNotCount($expectedCount, $haystack, $message = '')
  433. {
  434. if (!is_int($expectedCount)) {
  435. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'integer');
  436. }
  437. if (!$haystack instanceof Countable &&
  438. !$haystack instanceof Traversable &&
  439. !is_array($haystack)) {
  440. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'countable or traversable');
  441. }
  442. $constraint = new PHPUnit_Framework_Constraint_Not(
  443. new PHPUnit_Framework_Constraint_Count($expectedCount)
  444. );
  445. self::assertThat($haystack, $constraint, $message);
  446. }
  447. /**
  448. * Asserts the number of elements of an array, Countable or Traversable
  449. * that is stored in an attribute.
  450. *
  451. * @param integer $expectedCount
  452. * @param string $haystackAttributeName
  453. * @param mixed $haystackClassOrObject
  454. * @param string $message
  455. * @since Method available since Release 3.6.0
  456. */
  457. public static function assertAttributeNotCount($expectedCount, $haystackAttributeName, $haystackClassOrObject, $message = '')
  458. {
  459. self::assertNotCount(
  460. $expectedCount,
  461. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  462. $message
  463. );
  464. }
  465. /**
  466. * Asserts that two variables are equal.
  467. *
  468. * @param mixed $expected
  469. * @param mixed $actual
  470. * @param string $message
  471. * @param float $delta
  472. * @param integer $maxDepth
  473. * @param boolean $canonicalize
  474. * @param boolean $ignoreCase
  475. */
  476. public static function assertEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
  477. {
  478. $constraint = new PHPUnit_Framework_Constraint_IsEqual(
  479. $expected,
  480. $delta,
  481. $maxDepth,
  482. $canonicalize,
  483. $ignoreCase
  484. );
  485. self::assertThat($actual, $constraint, $message);
  486. }
  487. /**
  488. * Asserts that a variable is equal to an attribute of an object.
  489. *
  490. * @param mixed $expected
  491. * @param string $actualAttributeName
  492. * @param string $actualClassOrObject
  493. * @param string $message
  494. * @param float $delta
  495. * @param integer $maxDepth
  496. * @param boolean $canonicalize
  497. * @param boolean $ignoreCase
  498. */
  499. public static function assertAttributeEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
  500. {
  501. self::assertEquals(
  502. $expected,
  503. self::readAttribute($actualClassOrObject, $actualAttributeName),
  504. $message,
  505. $delta,
  506. $maxDepth,
  507. $canonicalize,
  508. $ignoreCase
  509. );
  510. }
  511. /**
  512. * Asserts that two variables are not equal.
  513. *
  514. * @param mixed $expected
  515. * @param mixed $actual
  516. * @param string $message
  517. * @param float $delta
  518. * @param integer $maxDepth
  519. * @param boolean $canonicalize
  520. * @param boolean $ignoreCase
  521. * @since Method available since Release 2.3.0
  522. */
  523. public static function assertNotEquals($expected, $actual, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
  524. {
  525. $constraint = new PHPUnit_Framework_Constraint_Not(
  526. new PHPUnit_Framework_Constraint_IsEqual(
  527. $expected,
  528. $delta,
  529. $maxDepth,
  530. $canonicalize,
  531. $ignoreCase
  532. )
  533. );
  534. self::assertThat($actual, $constraint, $message);
  535. }
  536. /**
  537. * Asserts that a variable is not equal to an attribute of an object.
  538. *
  539. * @param mixed $expected
  540. * @param string $actualAttributeName
  541. * @param string $actualClassOrObject
  542. * @param string $message
  543. * @param float $delta
  544. * @param integer $maxDepth
  545. * @param boolean $canonicalize
  546. * @param boolean $ignoreCase
  547. */
  548. public static function assertAttributeNotEquals($expected, $actualAttributeName, $actualClassOrObject, $message = '', $delta = 0.0, $maxDepth = 10, $canonicalize = false, $ignoreCase = false)
  549. {
  550. self::assertNotEquals(
  551. $expected,
  552. self::readAttribute($actualClassOrObject, $actualAttributeName),
  553. $message,
  554. $delta,
  555. $maxDepth,
  556. $canonicalize,
  557. $ignoreCase
  558. );
  559. }
  560. /**
  561. * Asserts that a variable is empty.
  562. *
  563. * @param mixed $actual
  564. * @param string $message
  565. * @throws PHPUnit_Framework_AssertionFailedError
  566. */
  567. public static function assertEmpty($actual, $message = '')
  568. {
  569. self::assertThat($actual, self::isEmpty(), $message);
  570. }
  571. /**
  572. * Asserts that a static attribute of a class or an attribute of an object
  573. * is empty.
  574. *
  575. * @param string $haystackAttributeName
  576. * @param mixed $haystackClassOrObject
  577. * @param string $message
  578. * @since Method available since Release 3.5.0
  579. */
  580. public static function assertAttributeEmpty($haystackAttributeName, $haystackClassOrObject, $message = '')
  581. {
  582. self::assertEmpty(
  583. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  584. $message
  585. );
  586. }
  587. /**
  588. * Asserts that a variable is not empty.
  589. *
  590. * @param mixed $actual
  591. * @param string $message
  592. * @throws PHPUnit_Framework_AssertionFailedError
  593. */
  594. public static function assertNotEmpty($actual, $message = '')
  595. {
  596. self::assertThat($actual, self::logicalNot(self::isEmpty()), $message);
  597. }
  598. /**
  599. * Asserts that a static attribute of a class or an attribute of an object
  600. * is not empty.
  601. *
  602. * @param string $haystackAttributeName
  603. * @param mixed $haystackClassOrObject
  604. * @param string $message
  605. * @since Method available since Release 3.5.0
  606. */
  607. public static function assertAttributeNotEmpty($haystackAttributeName, $haystackClassOrObject, $message = '')
  608. {
  609. self::assertNotEmpty(
  610. self::readAttribute($haystackClassOrObject, $haystackAttributeName),
  611. $message
  612. );
  613. }
  614. /**
  615. * Asserts that a value is greater than another value.
  616. *
  617. * @param mixed $expected
  618. * @param mixed $actual
  619. * @param string $message
  620. * @since Method available since Release 3.1.0
  621. */
  622. public static function assertGreaterThan($expected, $actual, $message = '')
  623. {
  624. self::assertThat($actual, self::greaterThan($expected), $message);
  625. }
  626. /**
  627. * Asserts that an attribute is greater than another value.
  628. *
  629. * @param mixed $expected
  630. * @param string $actualAttributeName
  631. * @param string $actualClassOrObject
  632. * @param string $message
  633. * @since Method available since Release 3.1.0
  634. */
  635. public static function assertAttributeGreaterThan($expected, $actualAttributeName, $actualClassOrObject, $message = '')
  636. {
  637. self::assertGreaterThan(
  638. $expected,
  639. self::readAttribute($actualClassOrObject, $actualAttributeName),
  640. $message
  641. );
  642. }
  643. /**
  644. * Asserts that a value is greater than or equal to another value.
  645. *
  646. * @param mixed $expected
  647. * @param mixed $actual
  648. * @param string $message
  649. * @since Method available since Release 3.1.0
  650. */
  651. public static function assertGreaterThanOrEqual($expected, $actual, $message = '')
  652. {
  653. self::assertThat(
  654. $actual,
  655. self::greaterThanOrEqual($expected),
  656. $message
  657. );
  658. }
  659. /**
  660. * Asserts that an attribute is greater than or equal to another value.
  661. *
  662. * @param mixed $expected
  663. * @param string $actualAttributeName
  664. * @param string $actualClassOrObject
  665. * @param string $message
  666. * @since Method available since Release 3.1.0
  667. */
  668. public static function assertAttributeGreaterThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '')
  669. {
  670. self::assertGreaterThanOrEqual(
  671. $expected,
  672. self::readAttribute($actualClassOrObject, $actualAttributeName),
  673. $message
  674. );
  675. }
  676. /**
  677. * Asserts that a value is smaller than another value.
  678. *
  679. * @param mixed $expected
  680. * @param mixed $actual
  681. * @param string $message
  682. * @since Method available since Release 3.1.0
  683. */
  684. public static function assertLessThan($expected, $actual, $message = '')
  685. {
  686. self::assertThat($actual, self::lessThan($expected), $message);
  687. }
  688. /**
  689. * Asserts that an attribute is smaller than another value.
  690. *
  691. * @param mixed $expected
  692. * @param string $actualAttributeName
  693. * @param string $actualClassOrObject
  694. * @param string $message
  695. * @since Method available since Release 3.1.0
  696. */
  697. public static function assertAttributeLessThan($expected, $actualAttributeName, $actualClassOrObject, $message = '')
  698. {
  699. self::assertLessThan(
  700. $expected,
  701. self::readAttribute($actualClassOrObject, $actualAttributeName),
  702. $message
  703. );
  704. }
  705. /**
  706. * Asserts that a value is smaller than or equal to another value.
  707. *
  708. * @param mixed $expected
  709. * @param mixed $actual
  710. * @param string $message
  711. * @since Method available since Release 3.1.0
  712. */
  713. public static function assertLessThanOrEqual($expected, $actual, $message = '')
  714. {
  715. self::assertThat($actual, self::lessThanOrEqual($expected), $message);
  716. }
  717. /**
  718. * Asserts that an attribute is smaller than or equal to another value.
  719. *
  720. * @param mixed $expected
  721. * @param string $actualAttributeName
  722. * @param string $actualClassOrObject
  723. * @param string $message
  724. * @since Method available since Release 3.1.0
  725. */
  726. public static function assertAttributeLessThanOrEqual($expected, $actualAttributeName, $actualClassOrObject, $message = '')
  727. {
  728. self::assertLessThanOrEqual(
  729. $expected,
  730. self::readAttribute($actualClassOrObject, $actualAttributeName),
  731. $message
  732. );
  733. }
  734. /**
  735. * Asserts that the contents of one file is equal to the contents of another
  736. * file.
  737. *
  738. * @param string $expected
  739. * @param string $actual
  740. * @param string $message
  741. * @param boolean $canonicalize
  742. * @param boolean $ignoreCase
  743. * @since Method available since Release 3.2.14
  744. */
  745. public static function assertFileEquals($expected, $actual, $message = '', $canonicalize = false, $ignoreCase = false)
  746. {
  747. self::assertFileExists($expected, $message);
  748. self::assertFileExists($actual, $message);
  749. self::assertEquals(
  750. file_get_contents($expected),
  751. file_get_contents($actual),
  752. $message,
  753. 0,
  754. 10,
  755. $canonicalize,
  756. $ignoreCase
  757. );
  758. }
  759. /**
  760. * Asserts that the contents of one file is not equal to the contents of
  761. * another file.
  762. *
  763. * @param string $expected
  764. * @param string $actual
  765. * @param string $message
  766. * @param boolean $canonicalize
  767. * @param boolean $ignoreCase
  768. * @since Method available since Release 3.2.14
  769. */
  770. public static function assertFileNotEquals($expected, $actual, $message = '', $canonicalize = false, $ignoreCase = false)
  771. {
  772. self::assertFileExists($expected, $message);
  773. self::assertFileExists($actual, $message);
  774. self::assertNotEquals(
  775. file_get_contents($expected),
  776. file_get_contents($actual),
  777. $message,
  778. 0,
  779. 10,
  780. $canonicalize,
  781. $ignoreCase
  782. );
  783. }
  784. /**
  785. * Asserts that the contents of a string is equal
  786. * to the contents of a file.
  787. *
  788. * @param string $expectedFile
  789. * @param string $actualString
  790. * @param string $message
  791. * @param boolean $canonicalize
  792. * @param boolean $ignoreCase
  793. * @since Method available since Release 3.3.0
  794. */
  795. public static function assertStringEqualsFile($expectedFile, $actualString, $message = '', $canonicalize = false, $ignoreCase = false)
  796. {
  797. self::assertFileExists($expectedFile, $message);
  798. self::assertEquals(
  799. file_get_contents($expectedFile),
  800. $actualString,
  801. $message,
  802. 0,
  803. 10,
  804. $canonicalize,
  805. $ignoreCase
  806. );
  807. }
  808. /**
  809. * Asserts that the contents of a string is not equal
  810. * to the contents of a file.
  811. *
  812. * @param string $expectedFile
  813. * @param string $actualString
  814. * @param string $message
  815. * @param boolean $canonicalize
  816. * @param boolean $ignoreCase
  817. * @since Method available since Release 3.3.0
  818. */
  819. public static function assertStringNotEqualsFile($expectedFile, $actualString, $message = '', $canonicalize = false, $ignoreCase = false)
  820. {
  821. self::assertFileExists($expectedFile, $message);
  822. self::assertNotEquals(
  823. file_get_contents($expectedFile),
  824. $actualString,
  825. $message,
  826. 0,
  827. 10,
  828. $canonicalize,
  829. $ignoreCase
  830. );
  831. }
  832. /**
  833. * Asserts that a file exists.
  834. *
  835. * @param string $filename
  836. * @param string $message
  837. * @since Method available since Release 3.0.0
  838. */
  839. public static function assertFileExists($filename, $message = '')
  840. {
  841. if (!is_string($filename)) {
  842. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  843. }
  844. $constraint = new PHPUnit_Framework_Constraint_FileExists;
  845. self::assertThat($filename, $constraint, $message);
  846. }
  847. /**
  848. * Asserts that a file does not exist.
  849. *
  850. * @param string $filename
  851. * @param string $message
  852. * @since Method available since Release 3.0.0
  853. */
  854. public static function assertFileNotExists($filename, $message = '')
  855. {
  856. if (!is_string($filename)) {
  857. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  858. }
  859. $constraint = new PHPUnit_Framework_Constraint_Not(
  860. new PHPUnit_Framework_Constraint_FileExists
  861. );
  862. self::assertThat($filename, $constraint, $message);
  863. }
  864. /**
  865. * Asserts that a condition is true.
  866. *
  867. * @param boolean $condition
  868. * @param string $message
  869. * @throws PHPUnit_Framework_AssertionFailedError
  870. */
  871. public static function assertTrue($condition, $message = '')
  872. {
  873. self::assertThat($condition, self::isTrue(), $message);
  874. }
  875. /**
  876. * Asserts that a condition is not true.
  877. *
  878. * @param boolean $condition
  879. * @param string $message
  880. * @throws PHPUnit_Framework_AssertionFailedError
  881. */
  882. public static function assertNotTrue($condition, $message = '')
  883. {
  884. self::assertThat($condition, self::logicalNot(self::isTrue()), $message);
  885. }
  886. /**
  887. * Asserts that a condition is false.
  888. *
  889. * @param boolean $condition
  890. * @param string $message
  891. * @throws PHPUnit_Framework_AssertionFailedError
  892. */
  893. public static function assertFalse($condition, $message = '')
  894. {
  895. self::assertThat($condition, self::isFalse(), $message);
  896. }
  897. /**
  898. * Asserts that a condition is not false.
  899. *
  900. * @param boolean $condition
  901. * @param string $message
  902. * @throws PHPUnit_Framework_AssertionFailedError
  903. */
  904. public static function assertNotFalse($condition, $message = '')
  905. {
  906. self::assertThat($condition, self::logicalNot(self::isFalse()), $message);
  907. }
  908. /**
  909. * Asserts that a variable is not null.
  910. *
  911. * @param mixed $actual
  912. * @param string $message
  913. */
  914. public static function assertNotNull($actual, $message = '')
  915. {
  916. self::assertThat($actual, self::logicalNot(self::isNull()), $message);
  917. }
  918. /**
  919. * Asserts that a variable is null.
  920. *
  921. * @param mixed $actual
  922. * @param string $message
  923. */
  924. public static function assertNull($actual, $message = '')
  925. {
  926. self::assertThat($actual, self::isNull(), $message);
  927. }
  928. /**
  929. * Asserts that a class has a specified attribute.
  930. *
  931. * @param string $attributeName
  932. * @param string $className
  933. * @param string $message
  934. * @since Method available since Release 3.1.0
  935. */
  936. public static function assertClassHasAttribute($attributeName, $className, $message = '')
  937. {
  938. if (!is_string($attributeName)) {
  939. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  940. }
  941. if (!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName)) {
  942. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
  943. }
  944. if (!is_string($className) || !class_exists($className, false)) {
  945. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
  946. }
  947. $constraint = new PHPUnit_Framework_Constraint_ClassHasAttribute(
  948. $attributeName
  949. );
  950. self::assertThat($className, $constraint, $message);
  951. }
  952. /**
  953. * Asserts that a class does not have a specified attribute.
  954. *
  955. * @param string $attributeName
  956. * @param string $className
  957. * @param string $message
  958. * @since Method available since Release 3.1.0
  959. */
  960. public static function assertClassNotHasAttribute($attributeName, $className, $message = '')
  961. {
  962. if (!is_string($attributeName)) {
  963. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  964. }
  965. if (!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName)) {
  966. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
  967. }
  968. if (!is_string($className) || !class_exists($className, false)) {
  969. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
  970. }
  971. $constraint = new PHPUnit_Framework_Constraint_Not(
  972. new PHPUnit_Framework_Constraint_ClassHasAttribute($attributeName)
  973. );
  974. self::assertThat($className, $constraint, $message);
  975. }
  976. /**
  977. * Asserts that a class has a specified static attribute.
  978. *
  979. * @param string $attributeName
  980. * @param string $className
  981. * @param string $message
  982. * @since Method available since Release 3.1.0
  983. */
  984. public static function assertClassHasStaticAttribute($attributeName, $className, $message = '')
  985. {
  986. if (!is_string($attributeName)) {
  987. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  988. }
  989. if (!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName)) {
  990. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
  991. }
  992. if (!is_string($className) || !class_exists($className, false)) {
  993. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
  994. }
  995. $constraint = new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
  996. $attributeName
  997. );
  998. self::assertThat($className, $constraint, $message);
  999. }
  1000. /**
  1001. * Asserts that a class does not have a specified static attribute.
  1002. *
  1003. * @param string $attributeName
  1004. * @param string $className
  1005. * @param string $message
  1006. * @since Method available since Release 3.1.0
  1007. */
  1008. public static function assertClassNotHasStaticAttribute($attributeName, $className, $message = '')
  1009. {
  1010. if (!is_string($attributeName)) {
  1011. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1012. }
  1013. if (!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName)) {
  1014. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
  1015. }
  1016. if (!is_string($className) || !class_exists($className, false)) {
  1017. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'class name');
  1018. }
  1019. $constraint = new PHPUnit_Framework_Constraint_Not(
  1020. new PHPUnit_Framework_Constraint_ClassHasStaticAttribute(
  1021. $attributeName
  1022. )
  1023. );
  1024. self::assertThat($className, $constraint, $message);
  1025. }
  1026. /**
  1027. * Asserts that an object has a specified attribute.
  1028. *
  1029. * @param string $attributeName
  1030. * @param object $object
  1031. * @param string $message
  1032. * @since Method available since Release 3.0.0
  1033. */
  1034. public static function assertObjectHasAttribute($attributeName, $object, $message = '')
  1035. {
  1036. if (!is_string($attributeName)) {
  1037. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1038. }
  1039. if (!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName)) {
  1040. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
  1041. }
  1042. if (!is_object($object)) {
  1043. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
  1044. }
  1045. $constraint = new PHPUnit_Framework_Constraint_ObjectHasAttribute(
  1046. $attributeName
  1047. );
  1048. self::assertThat($object, $constraint, $message);
  1049. }
  1050. /**
  1051. * Asserts that an object does not have a specified attribute.
  1052. *
  1053. * @param string $attributeName
  1054. * @param object $object
  1055. * @param string $message
  1056. * @since Method available since Release 3.0.0
  1057. */
  1058. public static function assertObjectNotHasAttribute($attributeName, $object, $message = '')
  1059. {
  1060. if (!is_string($attributeName)) {
  1061. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1062. }
  1063. if (!preg_match('/[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $attributeName)) {
  1064. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'valid attribute name');
  1065. }
  1066. if (!is_object($object)) {
  1067. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'object');
  1068. }
  1069. $constraint = new PHPUnit_Framework_Constraint_Not(
  1070. new PHPUnit_Framework_Constraint_ObjectHasAttribute($attributeName)
  1071. );
  1072. self::assertThat($object, $constraint, $message);
  1073. }
  1074. /**
  1075. * Asserts that two variables have the same type and value.
  1076. * Used on objects, it asserts that two variables reference
  1077. * the same object.
  1078. *
  1079. * @param mixed $expected
  1080. * @param mixed $actual
  1081. * @param string $message
  1082. */
  1083. public static function assertSame($expected, $actual, $message = '')
  1084. {
  1085. if (is_bool($expected) && is_bool($actual)) {
  1086. self::assertEquals($expected, $actual, $message);
  1087. } else {
  1088. $constraint = new PHPUnit_Framework_Constraint_IsIdentical(
  1089. $expected
  1090. );
  1091. self::assertThat($actual, $constraint, $message);
  1092. }
  1093. }
  1094. /**
  1095. * Asserts that a variable and an attribute of an object have the same type
  1096. * and value.
  1097. *
  1098. * @param mixed $expected
  1099. * @param string $actualAttributeName
  1100. * @param object $actualClassOrObject
  1101. * @param string $message
  1102. */
  1103. public static function assertAttributeSame($expected, $actualAttributeName, $actualClassOrObject, $message = '')
  1104. {
  1105. self::assertSame(
  1106. $expected,
  1107. self::readAttribute($actualClassOrObject, $actualAttributeName),
  1108. $message
  1109. );
  1110. }
  1111. /**
  1112. * Asserts that two variables do not have the same type and value.
  1113. * Used on objects, it asserts that two variables do not reference
  1114. * the same object.
  1115. *
  1116. * @param mixed $expected
  1117. * @param mixed $actual
  1118. * @param string $message
  1119. */
  1120. public static function assertNotSame($expected, $actual, $message = '')
  1121. {
  1122. if (is_bool($expected) && is_bool($actual)) {
  1123. self::assertNotEquals($expected, $actual, $message);
  1124. } else {
  1125. $constraint = new PHPUnit_Framework_Constraint_Not(
  1126. new PHPUnit_Framework_Constraint_IsIdentical($expected)
  1127. );
  1128. self::assertThat($actual, $constraint, $message);
  1129. }
  1130. }
  1131. /**
  1132. * Asserts that a variable and an attribute of an object do not have the
  1133. * same type and value.
  1134. *
  1135. * @param mixed $expected
  1136. * @param string $actualAttributeName
  1137. * @param object $actualClassOrObject
  1138. * @param string $message
  1139. */
  1140. public static function assertAttributeNotSame($expected, $actualAttributeName, $actualClassOrObject, $message = '')
  1141. {
  1142. self::assertNotSame(
  1143. $expected,
  1144. self::readAttribute($actualClassOrObject, $actualAttributeName),
  1145. $message
  1146. );
  1147. }
  1148. /**
  1149. * Asserts that a variable is of a given type.
  1150. *
  1151. * @param string $expected
  1152. * @param mixed $actual
  1153. * @param string $message
  1154. * @since Method available since Release 3.5.0
  1155. */
  1156. public static function assertInstanceOf($expected, $actual, $message = '')
  1157. {
  1158. if (!(is_string($expected) && (class_exists($expected) || interface_exists($expected)))) {
  1159. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class or interface name');
  1160. }
  1161. $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf(
  1162. $expected
  1163. );
  1164. self::assertThat($actual, $constraint, $message);
  1165. }
  1166. /**
  1167. * Asserts that an attribute is of a given type.
  1168. *
  1169. * @param string $expected
  1170. * @param string $attributeName
  1171. * @param mixed $classOrObject
  1172. * @param string $message
  1173. * @since Method available since Release 3.5.0
  1174. */
  1175. public static function assertAttributeInstanceOf($expected, $attributeName, $classOrObject, $message = '')
  1176. {
  1177. self::assertInstanceOf(
  1178. $expected,
  1179. self::readAttribute($classOrObject, $attributeName),
  1180. $message
  1181. );
  1182. }
  1183. /**
  1184. * Asserts that a variable is not of a given type.
  1185. *
  1186. * @param string $expected
  1187. * @param mixed $actual
  1188. * @param string $message
  1189. * @since Method available since Release 3.5.0
  1190. */
  1191. public static function assertNotInstanceOf($expected, $actual, $message = '')
  1192. {
  1193. if (!(is_string($expected) && (class_exists($expected) || interface_exists($expected)))) {
  1194. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'class or interface name');
  1195. }
  1196. $constraint = new PHPUnit_Framework_Constraint_Not(
  1197. new PHPUnit_Framework_Constraint_IsInstanceOf($expected)
  1198. );
  1199. self::assertThat($actual, $constraint, $message);
  1200. }
  1201. /**
  1202. * Asserts that an attribute is of a given type.
  1203. *
  1204. * @param string $expected
  1205. * @param string $attributeName
  1206. * @param mixed $classOrObject
  1207. * @param string $message
  1208. * @since Method available since Release 3.5.0
  1209. */
  1210. public static function assertAttributeNotInstanceOf($expected, $attributeName, $classOrObject, $message = '')
  1211. {
  1212. self::assertNotInstanceOf(
  1213. $expected,
  1214. self::readAttribute($classOrObject, $attributeName),
  1215. $message
  1216. );
  1217. }
  1218. /**
  1219. * Asserts that a variable is of a given type.
  1220. *
  1221. * @param string $expected
  1222. * @param mixed $actual
  1223. * @param string $message
  1224. * @since Method available since Release 3.5.0
  1225. */
  1226. public static function assertInternalType($expected, $actual, $message = '')
  1227. {
  1228. if (!is_string($expected)) {
  1229. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1230. }
  1231. $constraint = new PHPUnit_Framework_Constraint_IsType(
  1232. $expected
  1233. );
  1234. self::assertThat($actual, $constraint, $message);
  1235. }
  1236. /**
  1237. * Asserts that an attribute is of a given type.
  1238. *
  1239. * @param string $expected
  1240. * @param string $attributeName
  1241. * @param mixed $classOrObject
  1242. * @param string $message
  1243. * @since Method available since Release 3.5.0
  1244. */
  1245. public static function assertAttributeInternalType($expected, $attributeName, $classOrObject, $message = '')
  1246. {
  1247. self::assertInternalType(
  1248. $expected,
  1249. self::readAttribute($classOrObject, $attributeName),
  1250. $message
  1251. );
  1252. }
  1253. /**
  1254. * Asserts that a variable is not of a given type.
  1255. *
  1256. * @param string $expected
  1257. * @param mixed $actual
  1258. * @param string $message
  1259. * @since Method available since Release 3.5.0
  1260. */
  1261. public static function assertNotInternalType($expected, $actual, $message = '')
  1262. {
  1263. if (!is_string($expected)) {
  1264. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1265. }
  1266. $constraint = new PHPUnit_Framework_Constraint_Not(
  1267. new PHPUnit_Framework_Constraint_IsType($expected)
  1268. );
  1269. self::assertThat($actual, $constraint, $message);
  1270. }
  1271. /**
  1272. * Asserts that an attribute is of a given type.
  1273. *
  1274. * @param string $expected
  1275. * @param string $attributeName
  1276. * @param mixed $classOrObject
  1277. * @param string $message
  1278. * @since Method available since Release 3.5.0
  1279. */
  1280. public static function assertAttributeNotInternalType($expected, $attributeName, $classOrObject, $message = '')
  1281. {
  1282. self::assertNotInternalType(
  1283. $expected,
  1284. self::readAttribute($classOrObject, $attributeName),
  1285. $message
  1286. );
  1287. }
  1288. /**
  1289. * Asserts that a string matches a given regular expression.
  1290. *
  1291. * @param string $pattern
  1292. * @param string $string
  1293. * @param string $message
  1294. */
  1295. public static function assertRegExp($pattern, $string, $message = '')
  1296. {
  1297. if (!is_string($pattern)) {
  1298. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1299. }
  1300. if (!is_string($string)) {
  1301. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1302. }
  1303. $constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern);
  1304. self::assertThat($string, $constraint, $message);
  1305. }
  1306. /**
  1307. * Asserts that a string does not match a given regular expression.
  1308. *
  1309. * @param string $pattern
  1310. * @param string $string
  1311. * @param string $message
  1312. * @since Method available since Release 2.1.0
  1313. */
  1314. public static function assertNotRegExp($pattern, $string, $message = '')
  1315. {
  1316. if (!is_string($pattern)) {
  1317. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1318. }
  1319. if (!is_string($string)) {
  1320. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1321. }
  1322. $constraint = new PHPUnit_Framework_Constraint_Not(
  1323. new PHPUnit_Framework_Constraint_PCREMatch($pattern)
  1324. );
  1325. self::assertThat($string, $constraint, $message);
  1326. }
  1327. /**
  1328. * Assert that the size of two arrays (or `Countable` or `Traversable` objects)
  1329. * is the same.
  1330. *
  1331. * @param array|Countable|Traversable $expected
  1332. * @param array|Countable|Traversable $actual
  1333. * @param string $message
  1334. */
  1335. public static function assertSameSize($expected, $actual, $message = '')
  1336. {
  1337. if (!$expected instanceof Countable &&
  1338. !$expected instanceof Traversable &&
  1339. !is_array($expected)) {
  1340. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'countable or traversable');
  1341. }
  1342. if (!$actual instanceof Countable &&
  1343. !$actual instanceof Traversable &&
  1344. !is_array($actual)) {
  1345. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'countable or traversable');
  1346. }
  1347. self::assertThat(
  1348. $actual,
  1349. new PHPUnit_Framework_Constraint_SameSize($expected),
  1350. $message
  1351. );
  1352. }
  1353. /**
  1354. * Assert that the size of two arrays (or `Countable` or `Traversable` objects)
  1355. * is not the same.
  1356. *
  1357. * @param array|Countable|Traversable $expected
  1358. * @param array|Countable|Traversable $actual
  1359. * @param string $message
  1360. */
  1361. public static function assertNotSameSize($expected, $actual, $message = '')
  1362. {
  1363. if (!$expected instanceof Countable &&
  1364. !$expected instanceof Traversable &&
  1365. !is_array($expected)) {
  1366. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'countable or traversable');
  1367. }
  1368. if (!$actual instanceof Countable &&
  1369. !$actual instanceof Traversable &&
  1370. !is_array($actual)) {
  1371. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'countable or traversable');
  1372. }
  1373. $constraint = new PHPUnit_Framework_Constraint_Not(
  1374. new PHPUnit_Framework_Constraint_SameSize($expected)
  1375. );
  1376. self::assertThat($actual, $constraint, $message);
  1377. }
  1378. /**
  1379. * Asserts that a string matches a given format string.
  1380. *
  1381. * @param string $format
  1382. * @param string $string
  1383. * @param string $message
  1384. * @since Method available since Release 3.5.0
  1385. */
  1386. public static function assertStringMatchesFormat($format, $string, $message = '')
  1387. {
  1388. if (!is_string($format)) {
  1389. throw PHPUnit_Util_InvalidA

Large files files are truncated, but you can click here to view the full file