PageRenderTime 57ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/plugins/org.phpsrc.eclipse.pti.library.pear_1.2.2.R20120127000000/php/library/PEAR/PHPUnit/Framework/Assert.php

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

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