PageRenderTime 55ms CodeModel.GetById 23ms RepoModel.GetById 0ms app.codeStats 0ms

/tests/PHPUnit/PHPUnit/Framework/Assert.php

https://bitbucket.org/cviolette/sugarcrm
PHP | 2620 lines | 1165 code | 252 blank | 1203 comment | 120 complexity | 9fb04b322536d7d7eb3d4816389d7eaf MD5 | raw file
Possible License(s): LGPL-2.1, MPL-2.0-no-copyleft-exception, 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) 2002-2011, 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 2002-2011 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 2002-2011 Sebastian Bergmann <sebastian@phpunit.de>
  52. * @license http://www.opensource.org/licenses/bsd-license.php BSD License
  53. * @version Release: 3.5.14
  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. * @deprecated
  1098. */
  1099. public static function assertType($expected, $actual, $message = '')
  1100. {
  1101. PHPUnit_Util_DeprecatedFeature_Logger::log(
  1102. 'assertType() will be removed in PHPUnit 3.6 and should no longer ' .
  1103. 'be used. assertInternalType() should be used for asserting ' .
  1104. 'internal types such as "integer" or "string" whereas ' .
  1105. 'assertInstanceOf() should be used for asserting that an object is ' .
  1106. 'an instance of a specified class or interface.'
  1107. );
  1108. if (is_string($expected)) {
  1109. if (PHPUnit_Util_Type::isType($expected)) {
  1110. $constraint = new PHPUnit_Framework_Constraint_IsType(
  1111. $expected
  1112. );
  1113. }
  1114. else if (class_exists($expected) || interface_exists($expected)) {
  1115. $constraint = new PHPUnit_Framework_Constraint_IsInstanceOf(
  1116. $expected
  1117. );
  1118. }
  1119. else {
  1120. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  1121. 1, 'class or interface name'
  1122. );
  1123. }
  1124. } else {
  1125. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1126. }
  1127. self::assertThat($actual, $constraint, $message);
  1128. }
  1129. /**
  1130. * Asserts that an attribute is of a given type.
  1131. *
  1132. * @param string $expected
  1133. * @param string $attributeName
  1134. * @param mixed $classOrObject
  1135. * @param string $message
  1136. * @since Method available since Release 3.4.0
  1137. * @deprecated
  1138. */
  1139. public static function assertAttributeType($expected, $attributeName, $classOrObject, $message = '')
  1140. {
  1141. PHPUnit_Util_DeprecatedFeature_Logger::log(
  1142. 'assertAttributeType() will be removed in PHPUnit 3.6 and should ' .
  1143. 'no longer be used. assertAttributeInternalType() should be used ' .
  1144. 'for asserting internal types such as "integer" or "string" ' .
  1145. 'whereas assertAttributeInstanceOf() should be used for asserting ' .
  1146. 'that an object is an instance of a specified class or interface.'
  1147. );
  1148. self::assertType(
  1149. $expected,
  1150. self::readAttribute($classOrObject, $attributeName),
  1151. $message
  1152. );
  1153. }
  1154. /**
  1155. * Asserts that a variable is not of a given type.
  1156. *
  1157. * @param string $expected
  1158. * @param mixed $actual
  1159. * @param string $message
  1160. * @since Method available since Release 2.2.0
  1161. * @deprecated
  1162. */
  1163. public static function assertNotType($expected, $actual, $message = '')
  1164. {
  1165. PHPUnit_Util_DeprecatedFeature_Logger::log(
  1166. 'assertNotType() will be removed in PHPUnit 3.6 and should no ' .
  1167. 'longer be used. assertNotInternalType() should be used for ' .
  1168. 'asserting internal types such as "integer" or "string" whereas ' .
  1169. 'assertNotInstanceOf() should be used for asserting that an object ' .
  1170. 'is not an instance of a specified class or interface.'
  1171. );
  1172. if (is_string($expected)) {
  1173. if (PHPUnit_Util_Type::isType($expected)) {
  1174. $constraint = new PHPUnit_Framework_Constraint_Not(
  1175. new PHPUnit_Framework_Constraint_IsType($expected)
  1176. );
  1177. }
  1178. else if (class_exists($expected) || interface_exists($expected)) {
  1179. $constraint = new PHPUnit_Framework_Constraint_Not(
  1180. new PHPUnit_Framework_Constraint_IsInstanceOf($expected)
  1181. );
  1182. }
  1183. else {
  1184. throw PHPUnit_Util_InvalidArgumentHelper::factory(
  1185. 1, 'class or interface name'
  1186. );
  1187. }
  1188. } else {
  1189. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1190. }
  1191. self::assertThat($actual, $constraint, $message);
  1192. }
  1193. /**
  1194. * Asserts that an attribute is of a given type.
  1195. *
  1196. * @param string $expected
  1197. * @param string $attributeName
  1198. * @param mixed $classOrObject
  1199. * @param string $message
  1200. * @since Method available since Release 3.4.0
  1201. * @deprecated
  1202. */
  1203. public static function assertAttributeNotType($expected, $attributeName, $classOrObject, $message = '')
  1204. {
  1205. PHPUnit_Util_DeprecatedFeature_Logger::log(
  1206. 'assertAttributeNotType() will be removed in PHPUnit 3.6 and ' .
  1207. 'should no longer be used. assertAttributeNotInternalType() should ' .
  1208. 'be used for asserting internal types such as "integer" or ' .
  1209. '"string" whereas assertAttributeNotInstanceOf() should be used ' .
  1210. 'for asserting that an object is an instance of a specified class ' .
  1211. 'or interface.'
  1212. );
  1213. self::assertNotType(
  1214. $expected,
  1215. self::readAttribute($classOrObject, $attributeName),
  1216. $message
  1217. );
  1218. }
  1219. /**
  1220. * Asserts that a string matches a given regular expression.
  1221. *
  1222. * @param string $pattern
  1223. * @param string $string
  1224. * @param string $message
  1225. */
  1226. public static function assertRegExp($pattern, $string, $message = '')
  1227. {
  1228. if (!is_string($pattern)) {
  1229. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1230. }
  1231. if (!is_string($string)) {
  1232. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1233. }
  1234. $constraint = new PHPUnit_Framework_Constraint_PCREMatch($pattern);
  1235. self::assertThat($string, $constraint, $message);
  1236. }
  1237. /**
  1238. * Asserts that a string does not match a given regular expression.
  1239. *
  1240. * @param string $pattern
  1241. * @param string $string
  1242. * @param string $message
  1243. * @since Method available since Release 2.1.0
  1244. */
  1245. public static function assertNotRegExp($pattern, $string, $message = '')
  1246. {
  1247. if (!is_string($pattern)) {
  1248. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1249. }
  1250. if (!is_string($string)) {
  1251. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1252. }
  1253. $constraint = new PHPUnit_Framework_Constraint_Not(
  1254. new PHPUnit_Framework_Constraint_PCREMatch($pattern)
  1255. );
  1256. self::assertThat($string, $constraint, $message);
  1257. }
  1258. /**
  1259. * Asserts that a string matches a given format string.
  1260. *
  1261. * @param string $format
  1262. * @param string $string
  1263. * @param string $message
  1264. * @since Method available since Release 3.5.0
  1265. */
  1266. public static function assertStringMatchesFormat($format, $string, $message = '')
  1267. {
  1268. if (!is_string($format)) {
  1269. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1270. }
  1271. if (!is_string($string)) {
  1272. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1273. }
  1274. $constraint = new PHPUnit_Framework_Constraint_StringMatches($format);
  1275. self::assertThat($string, $constraint, $message);
  1276. }
  1277. /**
  1278. * Asserts that a string does not match a given format string.
  1279. *
  1280. * @param string $format
  1281. * @param string $string
  1282. * @param string $message
  1283. * @since Method available since Release 3.5.0
  1284. */
  1285. public static function assertStringNotMatchesFormat($format, $string, $message = '')
  1286. {
  1287. if (!is_string($format)) {
  1288. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1289. }
  1290. if (!is_string($string)) {
  1291. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1292. }
  1293. $constraint = new PHPUnit_Framework_Constraint_Not(
  1294. new PHPUnit_Framework_Constraint_StringMatches($format)
  1295. );
  1296. self::assertThat($string, $constraint, $message);
  1297. }
  1298. /**
  1299. * Asserts that a string matches a given format file.
  1300. *
  1301. * @param string $formatFile
  1302. * @param string $string
  1303. * @param string $message
  1304. * @since Method available since Release 3.5.0
  1305. */
  1306. public static function assertStringMatchesFormatFile($formatFile, $string, $message = '')
  1307. {
  1308. self::assertFileExists($formatFile, $message);
  1309. if (!is_string($string)) {
  1310. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1311. }
  1312. $constraint = new PHPUnit_Framework_Constraint_StringMatches(
  1313. file_get_contents($formatFile)
  1314. );
  1315. self::assertThat($string, $constraint, $message);
  1316. }
  1317. /**
  1318. * Asserts that a string does not match a given format string.
  1319. *
  1320. * @param string $formatFile
  1321. * @param string $string
  1322. * @param string $message
  1323. * @since Method available since Release 3.5.0
  1324. */
  1325. public static function assertStringNotMatchesFormatFile($formatFile, $string, $message = '')
  1326. {
  1327. self::assertFileExists($formatFile, $message);
  1328. if (!is_string($string)) {
  1329. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1330. }
  1331. $constraint = new PHPUnit_Framework_Constraint_Not(
  1332. new PHPUnit_Framework_Constraint_StringMatches(
  1333. file_get_contents($formatFile)
  1334. )
  1335. );
  1336. self::assertThat($string, $constraint, $message);
  1337. }
  1338. /**
  1339. * Asserts that a string starts with a given prefix.
  1340. *
  1341. * @param string $prefix
  1342. * @param string $string
  1343. * @param string $message
  1344. * @since Method available since Release 3.4.0
  1345. */
  1346. public static function assertStringStartsWith($prefix, $string, $message = '')
  1347. {
  1348. if (!is_string($prefix)) {
  1349. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1350. }
  1351. if (!is_string($string)) {
  1352. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1353. }
  1354. $constraint = new PHPUnit_Framework_Constraint_StringStartsWith(
  1355. $prefix
  1356. );
  1357. self::assertThat($string, $constraint, $message);
  1358. }
  1359. /**
  1360. * Asserts that a string starts not with a given prefix.
  1361. *
  1362. * @param string $prefix
  1363. * @param string $string
  1364. * @param string $message
  1365. * @since Method available since Release 3.4.0
  1366. */
  1367. public static function assertStringStartsNotWith($prefix, $string, $message = '')
  1368. {
  1369. if (!is_string($prefix)) {
  1370. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1371. }
  1372. if (!is_string($string)) {
  1373. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1374. }
  1375. $constraint = new PHPUnit_Framework_Constraint_Not(
  1376. new PHPUnit_Framework_Constraint_StringStartsWith($prefix)
  1377. );
  1378. self::assertThat($string, $constraint, $message);
  1379. }
  1380. /**
  1381. * Asserts that a string ends with a given prefix.
  1382. *
  1383. * @param string $suffix
  1384. * @param string $string
  1385. * @param string $message
  1386. * @since Method available since Release 3.4.0
  1387. */
  1388. public static function assertStringEndsWith($suffix, $string, $message = '')
  1389. {
  1390. if (!is_string($suffix)) {
  1391. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1392. }
  1393. if (!is_string($string)) {
  1394. throw PHPUnit_Util_InvalidArgumentHelper::factory(2, 'string');
  1395. }
  1396. $constraint = new PHPUnit_Framework_Constraint_StringEndsWith($suffix);
  1397. self::assertThat($string, $constraint, $message);
  1398. }
  1399. /**
  1400. * Asserts that a string ends not with a given prefix.
  1401. *
  1402. * @param string $suffix
  1403. * @param string $string
  1404. * @param string $message
  1405. * @since Method available since Release 3.4.0
  1406. */
  1407. public static function assertStringEndsNotWith($suffix, $string, $message = '')
  1408. {
  1409. if (!is_string($suffix)) {
  1410. throw PHPUnit_Util_InvalidArgumentHelper::factory(1, 'string');
  1411. }
  1412. if (!is_string

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