PageRenderTime 46ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/vendor/hamcrest/hamcrest-php/hamcrest/Hamcrest/Matchers.php

https://gitlab.com/ealexis.t/trends
PHP | 713 lines | 325 code | 81 blank | 307 comment | 0 complexity | 032eaf0369c1b26eff4ea0d606e81977 MD5 | raw file
  1. <?php
  2. /*
  3. Copyright (c) 2009-2010 hamcrest.org
  4. */
  5. // This file is generated from the static method @factory doctags.
  6. namespace Hamcrest;
  7. /**
  8. * A series of static factories for all hamcrest matchers.
  9. */
  10. class Matchers
  11. {
  12. /**
  13. * Evaluates to true only if each $matcher[$i] is satisfied by $array[$i].
  14. */
  15. public static function anArray(/* args... */)
  16. {
  17. $args = func_get_args();
  18. return call_user_func_array(array('\Hamcrest\Arrays\IsArray', 'anArray'), $args);
  19. }
  20. /**
  21. * Evaluates to true if any item in an array satisfies the given matcher.
  22. *
  23. * @param mixed $item as a {@link Hamcrest\Matcher} or a value.
  24. *
  25. * @return \Hamcrest\Arrays\IsArrayContaining
  26. */
  27. public static function hasItemInArray($item)
  28. {
  29. return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item);
  30. }
  31. /**
  32. * Evaluates to true if any item in an array satisfies the given matcher.
  33. *
  34. * @param mixed $item as a {@link Hamcrest\Matcher} or a value.
  35. *
  36. * @return \Hamcrest\Arrays\IsArrayContaining
  37. */
  38. public static function hasValue($item)
  39. {
  40. return \Hamcrest\Arrays\IsArrayContaining::hasItemInArray($item);
  41. }
  42. /**
  43. * An array with elements that match the given matchers.
  44. */
  45. public static function arrayContainingInAnyOrder(/* args... */)
  46. {
  47. $args = func_get_args();
  48. return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args);
  49. }
  50. /**
  51. * An array with elements that match the given matchers.
  52. */
  53. public static function containsInAnyOrder(/* args... */)
  54. {
  55. $args = func_get_args();
  56. return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInAnyOrder', 'arrayContainingInAnyOrder'), $args);
  57. }
  58. /**
  59. * An array with elements that match the given matchers in the same order.
  60. */
  61. public static function arrayContaining(/* args... */)
  62. {
  63. $args = func_get_args();
  64. return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args);
  65. }
  66. /**
  67. * An array with elements that match the given matchers in the same order.
  68. */
  69. public static function contains(/* args... */)
  70. {
  71. $args = func_get_args();
  72. return call_user_func_array(array('\Hamcrest\Arrays\IsArrayContainingInOrder', 'arrayContaining'), $args);
  73. }
  74. /**
  75. * Evaluates to true if any key in an array matches the given matcher.
  76. *
  77. * @param mixed $key as a {@link Hamcrest\Matcher} or a value.
  78. *
  79. * @return \Hamcrest\Arrays\IsArrayContainingKey
  80. */
  81. public static function hasKeyInArray($key)
  82. {
  83. return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key);
  84. }
  85. /**
  86. * Evaluates to true if any key in an array matches the given matcher.
  87. *
  88. * @param mixed $key as a {@link Hamcrest\Matcher} or a value.
  89. *
  90. * @return \Hamcrest\Arrays\IsArrayContainingKey
  91. */
  92. public static function hasKey($key)
  93. {
  94. return \Hamcrest\Arrays\IsArrayContainingKey::hasKeyInArray($key);
  95. }
  96. /**
  97. * Test if an array has both an key and value in parity with each other.
  98. */
  99. public static function hasKeyValuePair($key, $value)
  100. {
  101. return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value);
  102. }
  103. /**
  104. * Test if an array has both an key and value in parity with each other.
  105. */
  106. public static function hasEntry($key, $value)
  107. {
  108. return \Hamcrest\Arrays\IsArrayContainingKeyValuePair::hasKeyValuePair($key, $value);
  109. }
  110. /**
  111. * Does array size satisfy a given matcher?
  112. *
  113. * @param \Hamcrest\Matcher|int $size as a {@link Hamcrest\Matcher} or a value.
  114. *
  115. * @return \Hamcrest\Arrays\IsArrayWithSize
  116. */
  117. public static function arrayWithSize($size)
  118. {
  119. return \Hamcrest\Arrays\IsArrayWithSize::arrayWithSize($size);
  120. }
  121. /**
  122. * Matches an empty array.
  123. */
  124. public static function emptyArray()
  125. {
  126. return \Hamcrest\Arrays\IsArrayWithSize::emptyArray();
  127. }
  128. /**
  129. * Matches an empty array.
  130. */
  131. public static function nonEmptyArray()
  132. {
  133. return \Hamcrest\Arrays\IsArrayWithSize::nonEmptyArray();
  134. }
  135. /**
  136. * Returns true if traversable is empty.
  137. */
  138. public static function emptyTraversable()
  139. {
  140. return \Hamcrest\Collection\IsEmptyTraversable::emptyTraversable();
  141. }
  142. /**
  143. * Returns true if traversable is not empty.
  144. */
  145. public static function nonEmptyTraversable()
  146. {
  147. return \Hamcrest\Collection\IsEmptyTraversable::nonEmptyTraversable();
  148. }
  149. /**
  150. * Does traversable size satisfy a given matcher?
  151. */
  152. public static function traversableWithSize($size)
  153. {
  154. return \Hamcrest\Collection\IsTraversableWithSize::traversableWithSize($size);
  155. }
  156. /**
  157. * Evaluates to true only if ALL of the passed in matchers evaluate to true.
  158. */
  159. public static function allOf(/* args... */)
  160. {
  161. $args = func_get_args();
  162. return call_user_func_array(array('\Hamcrest\Core\AllOf', 'allOf'), $args);
  163. }
  164. /**
  165. * Evaluates to true if ANY of the passed in matchers evaluate to true.
  166. */
  167. public static function anyOf(/* args... */)
  168. {
  169. $args = func_get_args();
  170. return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'anyOf'), $args);
  171. }
  172. /**
  173. * Evaluates to false if ANY of the passed in matchers evaluate to true.
  174. */
  175. public static function noneOf(/* args... */)
  176. {
  177. $args = func_get_args();
  178. return call_user_func_array(array('\Hamcrest\Core\AnyOf', 'noneOf'), $args);
  179. }
  180. /**
  181. * This is useful for fluently combining matchers that must both pass.
  182. * For example:
  183. * <pre>
  184. * assertThat($string, both(containsString("a"))->andAlso(containsString("b")));
  185. * </pre>
  186. */
  187. public static function both(\Hamcrest\Matcher $matcher)
  188. {
  189. return \Hamcrest\Core\CombinableMatcher::both($matcher);
  190. }
  191. /**
  192. * This is useful for fluently combining matchers where either may pass,
  193. * for example:
  194. * <pre>
  195. * assertThat($string, either(containsString("a"))->orElse(containsString("b")));
  196. * </pre>
  197. */
  198. public static function either(\Hamcrest\Matcher $matcher)
  199. {
  200. return \Hamcrest\Core\CombinableMatcher::either($matcher);
  201. }
  202. /**
  203. * Wraps an existing matcher and overrides the description when it fails.
  204. */
  205. public static function describedAs(/* args... */)
  206. {
  207. $args = func_get_args();
  208. return call_user_func_array(array('\Hamcrest\Core\DescribedAs', 'describedAs'), $args);
  209. }
  210. /**
  211. * @param Matcher $itemMatcher
  212. * A matcher to apply to every element in an array.
  213. *
  214. * @return \Hamcrest\Core\Every
  215. * Evaluates to TRUE for a collection in which every item matches $itemMatcher
  216. */
  217. public static function everyItem(\Hamcrest\Matcher $itemMatcher)
  218. {
  219. return \Hamcrest\Core\Every::everyItem($itemMatcher);
  220. }
  221. /**
  222. * Does array size satisfy a given matcher?
  223. */
  224. public static function hasToString($matcher)
  225. {
  226. return \Hamcrest\Core\HasToString::hasToString($matcher);
  227. }
  228. /**
  229. * Decorates another Matcher, retaining the behavior but allowing tests
  230. * to be slightly more expressive.
  231. *
  232. * For example: assertThat($cheese, equalTo($smelly))
  233. * vs. assertThat($cheese, is(equalTo($smelly)))
  234. */
  235. public static function is($value)
  236. {
  237. return \Hamcrest\Core\Is::is($value);
  238. }
  239. /**
  240. * This matcher always evaluates to true.
  241. *
  242. * @param string $description A meaningful string used when describing itself.
  243. *
  244. * @return \Hamcrest\Core\IsAnything
  245. */
  246. public static function anything($description = 'ANYTHING')
  247. {
  248. return \Hamcrest\Core\IsAnything::anything($description);
  249. }
  250. /**
  251. * Test if the value is an array containing this matcher.
  252. *
  253. * Example:
  254. * <pre>
  255. * assertThat(array('a', 'b'), hasItem(equalTo('b')));
  256. * //Convenience defaults to equalTo()
  257. * assertThat(array('a', 'b'), hasItem('b'));
  258. * </pre>
  259. */
  260. public static function hasItem(/* args... */)
  261. {
  262. $args = func_get_args();
  263. return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItem'), $args);
  264. }
  265. /**
  266. * Test if the value is an array containing elements that match all of these
  267. * matchers.
  268. *
  269. * Example:
  270. * <pre>
  271. * assertThat(array('a', 'b', 'c'), hasItems(equalTo('a'), equalTo('b')));
  272. * </pre>
  273. */
  274. public static function hasItems(/* args... */)
  275. {
  276. $args = func_get_args();
  277. return call_user_func_array(array('\Hamcrest\Core\IsCollectionContaining', 'hasItems'), $args);
  278. }
  279. /**
  280. * Is the value equal to another value, as tested by the use of the "=="
  281. * comparison operator?
  282. */
  283. public static function equalTo($item)
  284. {
  285. return \Hamcrest\Core\IsEqual::equalTo($item);
  286. }
  287. /**
  288. * Tests of the value is identical to $value as tested by the "===" operator.
  289. */
  290. public static function identicalTo($value)
  291. {
  292. return \Hamcrest\Core\IsIdentical::identicalTo($value);
  293. }
  294. /**
  295. * Is the value an instance of a particular type?
  296. * This version assumes no relationship between the required type and
  297. * the signature of the method that sets it up, for example in
  298. * <code>assertThat($anObject, anInstanceOf('Thing'));</code>
  299. */
  300. public static function anInstanceOf($theClass)
  301. {
  302. return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass);
  303. }
  304. /**
  305. * Is the value an instance of a particular type?
  306. * This version assumes no relationship between the required type and
  307. * the signature of the method that sets it up, for example in
  308. * <code>assertThat($anObject, anInstanceOf('Thing'));</code>
  309. */
  310. public static function any($theClass)
  311. {
  312. return \Hamcrest\Core\IsInstanceOf::anInstanceOf($theClass);
  313. }
  314. /**
  315. * Matches if value does not match $value.
  316. */
  317. public static function not($value)
  318. {
  319. return \Hamcrest\Core\IsNot::not($value);
  320. }
  321. /**
  322. * Matches if value is null.
  323. */
  324. public static function nullValue()
  325. {
  326. return \Hamcrest\Core\IsNull::nullValue();
  327. }
  328. /**
  329. * Matches if value is not null.
  330. */
  331. public static function notNullValue()
  332. {
  333. return \Hamcrest\Core\IsNull::notNullValue();
  334. }
  335. /**
  336. * Creates a new instance of IsSame.
  337. *
  338. * @param mixed $object
  339. * The predicate evaluates to true only when the argument is
  340. * this object.
  341. *
  342. * @return \Hamcrest\Core\IsSame
  343. */
  344. public static function sameInstance($object)
  345. {
  346. return \Hamcrest\Core\IsSame::sameInstance($object);
  347. }
  348. /**
  349. * Is the value a particular built-in type?
  350. */
  351. public static function typeOf($theType)
  352. {
  353. return \Hamcrest\Core\IsTypeOf::typeOf($theType);
  354. }
  355. /**
  356. * Matches if value (class, object, or array) has named $property.
  357. */
  358. public static function set($property)
  359. {
  360. return \Hamcrest\Core\Set::set($property);
  361. }
  362. /**
  363. * Matches if value (class, object, or array) does not have named $property.
  364. */
  365. public static function notSet($property)
  366. {
  367. return \Hamcrest\Core\Set::notSet($property);
  368. }
  369. /**
  370. * Matches if value is a number equal to $value within some range of
  371. * acceptable error $delta.
  372. */
  373. public static function closeTo($value, $delta)
  374. {
  375. return \Hamcrest\Number\IsCloseTo::closeTo($value, $delta);
  376. }
  377. /**
  378. * The value is not > $value, nor < $value.
  379. */
  380. public static function comparesEqualTo($value)
  381. {
  382. return \Hamcrest\Number\OrderingComparison::comparesEqualTo($value);
  383. }
  384. /**
  385. * The value is > $value.
  386. */
  387. public static function greaterThan($value)
  388. {
  389. return \Hamcrest\Number\OrderingComparison::greaterThan($value);
  390. }
  391. /**
  392. * The value is >= $value.
  393. */
  394. public static function greaterThanOrEqualTo($value)
  395. {
  396. return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value);
  397. }
  398. /**
  399. * The value is >= $value.
  400. */
  401. public static function atLeast($value)
  402. {
  403. return \Hamcrest\Number\OrderingComparison::greaterThanOrEqualTo($value);
  404. }
  405. /**
  406. * The value is < $value.
  407. */
  408. public static function lessThan($value)
  409. {
  410. return \Hamcrest\Number\OrderingComparison::lessThan($value);
  411. }
  412. /**
  413. * The value is <= $value.
  414. */
  415. public static function lessThanOrEqualTo($value)
  416. {
  417. return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value);
  418. }
  419. /**
  420. * The value is <= $value.
  421. */
  422. public static function atMost($value)
  423. {
  424. return \Hamcrest\Number\OrderingComparison::lessThanOrEqualTo($value);
  425. }
  426. /**
  427. * Matches if value is a zero-length string.
  428. */
  429. public static function isEmptyString()
  430. {
  431. return \Hamcrest\Text\IsEmptyString::isEmptyString();
  432. }
  433. /**
  434. * Matches if value is a zero-length string.
  435. */
  436. public static function emptyString()
  437. {
  438. return \Hamcrest\Text\IsEmptyString::isEmptyString();
  439. }
  440. /**
  441. * Matches if value is null or a zero-length string.
  442. */
  443. public static function isEmptyOrNullString()
  444. {
  445. return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString();
  446. }
  447. /**
  448. * Matches if value is null or a zero-length string.
  449. */
  450. public static function nullOrEmptyString()
  451. {
  452. return \Hamcrest\Text\IsEmptyString::isEmptyOrNullString();
  453. }
  454. /**
  455. * Matches if value is a non-zero-length string.
  456. */
  457. public static function isNonEmptyString()
  458. {
  459. return \Hamcrest\Text\IsEmptyString::isNonEmptyString();
  460. }
  461. /**
  462. * Matches if value is a non-zero-length string.
  463. */
  464. public static function nonEmptyString()
  465. {
  466. return \Hamcrest\Text\IsEmptyString::isNonEmptyString();
  467. }
  468. /**
  469. * Matches if value is a string equal to $string, regardless of the case.
  470. */
  471. public static function equalToIgnoringCase($string)
  472. {
  473. return \Hamcrest\Text\IsEqualIgnoringCase::equalToIgnoringCase($string);
  474. }
  475. /**
  476. * Matches if value is a string equal to $string, regardless of whitespace.
  477. */
  478. public static function equalToIgnoringWhiteSpace($string)
  479. {
  480. return \Hamcrest\Text\IsEqualIgnoringWhiteSpace::equalToIgnoringWhiteSpace($string);
  481. }
  482. /**
  483. * Matches if value is a string that matches regular expression $pattern.
  484. */
  485. public static function matchesPattern($pattern)
  486. {
  487. return \Hamcrest\Text\MatchesPattern::matchesPattern($pattern);
  488. }
  489. /**
  490. * Matches if value is a string that contains $substring.
  491. */
  492. public static function containsString($substring)
  493. {
  494. return \Hamcrest\Text\StringContains::containsString($substring);
  495. }
  496. /**
  497. * Matches if value is a string that contains $substring regardless of the case.
  498. */
  499. public static function containsStringIgnoringCase($substring)
  500. {
  501. return \Hamcrest\Text\StringContainsIgnoringCase::containsStringIgnoringCase($substring);
  502. }
  503. /**
  504. * Matches if value contains $substrings in a constrained order.
  505. */
  506. public static function stringContainsInOrder(/* args... */)
  507. {
  508. $args = func_get_args();
  509. return call_user_func_array(array('\Hamcrest\Text\StringContainsInOrder', 'stringContainsInOrder'), $args);
  510. }
  511. /**
  512. * Matches if value is a string that ends with $substring.
  513. */
  514. public static function endsWith($substring)
  515. {
  516. return \Hamcrest\Text\StringEndsWith::endsWith($substring);
  517. }
  518. /**
  519. * Matches if value is a string that starts with $substring.
  520. */
  521. public static function startsWith($substring)
  522. {
  523. return \Hamcrest\Text\StringStartsWith::startsWith($substring);
  524. }
  525. /**
  526. * Is the value an array?
  527. */
  528. public static function arrayValue()
  529. {
  530. return \Hamcrest\Type\IsArray::arrayValue();
  531. }
  532. /**
  533. * Is the value a boolean?
  534. */
  535. public static function booleanValue()
  536. {
  537. return \Hamcrest\Type\IsBoolean::booleanValue();
  538. }
  539. /**
  540. * Is the value a boolean?
  541. */
  542. public static function boolValue()
  543. {
  544. return \Hamcrest\Type\IsBoolean::booleanValue();
  545. }
  546. /**
  547. * Is the value callable?
  548. */
  549. public static function callableValue()
  550. {
  551. return \Hamcrest\Type\IsCallable::callableValue();
  552. }
  553. /**
  554. * Is the value a float/double?
  555. */
  556. public static function doubleValue()
  557. {
  558. return \Hamcrest\Type\IsDouble::doubleValue();
  559. }
  560. /**
  561. * Is the value a float/double?
  562. */
  563. public static function floatValue()
  564. {
  565. return \Hamcrest\Type\IsDouble::doubleValue();
  566. }
  567. /**
  568. * Is the value an integer?
  569. */
  570. public static function integerValue()
  571. {
  572. return \Hamcrest\Type\IsInteger::integerValue();
  573. }
  574. /**
  575. * Is the value an integer?
  576. */
  577. public static function intValue()
  578. {
  579. return \Hamcrest\Type\IsInteger::integerValue();
  580. }
  581. /**
  582. * Is the value a numeric?
  583. */
  584. public static function numericValue()
  585. {
  586. return \Hamcrest\Type\IsNumeric::numericValue();
  587. }
  588. /**
  589. * Is the value an object?
  590. */
  591. public static function objectValue()
  592. {
  593. return \Hamcrest\Type\IsObject::objectValue();
  594. }
  595. /**
  596. * Is the value an object?
  597. */
  598. public static function anObject()
  599. {
  600. return \Hamcrest\Type\IsObject::objectValue();
  601. }
  602. /**
  603. * Is the value a resource?
  604. */
  605. public static function resourceValue()
  606. {
  607. return \Hamcrest\Type\IsResource::resourceValue();
  608. }
  609. /**
  610. * Is the value a scalar (boolean, integer, double, or string)?
  611. */
  612. public static function scalarValue()
  613. {
  614. return \Hamcrest\Type\IsScalar::scalarValue();
  615. }
  616. /**
  617. * Is the value a string?
  618. */
  619. public static function stringValue()
  620. {
  621. return \Hamcrest\Type\IsString::stringValue();
  622. }
  623. /**
  624. * Wraps <code>$matcher</code> with {@link Hamcrest\Core\IsEqual)
  625. * if it's not a matcher and the XPath in <code>count()</code>
  626. * if it's an integer.
  627. */
  628. public static function hasXPath($xpath, $matcher = null)
  629. {
  630. return \Hamcrest\Xml\HasXPath::hasXPath($xpath, $matcher);
  631. }
  632. }