PageRenderTime 61ms CodeModel.GetById 28ms RepoModel.GetById 0ms app.codeStats 0ms

/vendor/phpunit/phpunit/PHPUnit/Framework/Assert.php

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

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