PageRenderTime 65ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 1ms

/PHPUnit/Framework/Assert.php

https://github.com/streetparade/phpunit
PHP | 2581 lines | 1142 code | 249 blank | 1190 comment | 124 complexity | 8991b2252ea85a3af63dd70b642436de MD5 | raw file

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

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

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