PageRenderTime 90ms CodeModel.GetById 39ms RepoModel.GetById 10ms app.codeStats 0ms

/lib/PHPUnit/Framework/Assert.php

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

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