PageRenderTime 47ms CodeModel.GetById 10ms RepoModel.GetById 1ms app.codeStats 0ms

/src/common/phpunit/PHPUnit/Framework/Assert.php

https://bitbucket.org/dukeofgaming/old_ether
PHP | 2232 lines | 971 code | 214 blank | 1047 comment | 100 complexity | 35119a0ded20ec0d967ca37704529b4f MD5 | raw file
Possible License(s): LGPL-3.0, BSD-3-Clause, CC-BY-SA-3.0, LGPL-2.1

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

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