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

/tests/unit/CodeGuy.php

https://github.com/instalic/Codeception
PHP | 726 lines | 224 code | 57 blank | 445 comment | 27 complexity | 3500f1abe9c740841cf78425f06fef26 MD5 | raw file
  1. <?php
  2. // This class was automatically generated by build task
  3. // You can change it manually, but it will be overwritten on next build
  4. use Codeception\Maybe;
  5. use Codeception\Module\Unit;
  6. use Codeception\Module\CodeHelper;
  7. use Codeception\Module\EmulateModuleHelper;
  8. /**
  9. * Inherited methods
  10. * @method void wantToTest($text)
  11. * @method void wantTo($text)
  12. * @method void amTesting($method)
  13. * @method void amTestingMethod($method)
  14. * @method void testMethod($signature)
  15. * @method void expectTo($prediction)
  16. * @method void expect($prediction)
  17. * @method void amGoingTo($argumentation)
  18. * @method void am($role)
  19. * @method void lookForwardTo($role)
  20. */
  21. class CodeGuy extends \Codeception\AbstractGuy
  22. {
  23. /**
  24. * Registers a class/method which will be tested.
  25. * When you run 'execute' this method will be invoked.
  26. * Please, note that it also updates the feature section of the scenario.
  27. *
  28. * For non-static methods:
  29. *
  30. * ``` php
  31. * <?php
  32. * $I->testMethod('ClassName.MethodName'); // I will need ClassName instance for this
  33. * ```
  34. *
  35. * For static methods:
  36. *
  37. * ``` php
  38. * <?php
  39. * $I->testMethod('ClassName::MethodName');
  40. * ```
  41. *
  42. * @param $signature
  43. * @see Unit::testMethod()
  44. *
  45. * ! This method is generated. DO NOT EDIT. !
  46. * ! Documentation taken from corresponding module !
  47. */
  48. public function testMethod($signature) {
  49. $this->scenario->action('testMethod', func_get_args());
  50. if ($this->scenario->running()) {
  51. $result = $this->scenario->runStep();
  52. return new Maybe($result);
  53. }
  54. return new Maybe();
  55. }
  56. /**
  57. * Adds a stub to the internal registry.
  58. * Use this command if you need to convert this stub to a mock.
  59. * Without adding the stub to registry you can't trace it's method invocations.
  60. *
  61. * @param $instance
  62. * @see Unit::haveFakeClass()
  63. *
  64. * ! This method is generated. DO NOT EDIT. !
  65. * ! Documentation taken from corresponding module !
  66. */
  67. public function haveFakeClass($instance) {
  68. $this->scenario->action('haveFakeClass', func_get_args());
  69. if ($this->scenario->running()) {
  70. $result = $this->scenario->runStep();
  71. return new Maybe($result);
  72. }
  73. return new Maybe();
  74. }
  75. /**
  76. * Alias for haveFakeClass
  77. *
  78. * @alias haveFakeClass
  79. * @param $instance
  80. * @see Unit::haveStub()
  81. *
  82. * ! This method is generated. DO NOT EDIT. !
  83. * ! Documentation taken from corresponding module !
  84. */
  85. public function haveStub($instance) {
  86. $this->scenario->action('haveStub', func_get_args());
  87. if ($this->scenario->running()) {
  88. $result = $this->scenario->runStep();
  89. return new Maybe($result);
  90. }
  91. return new Maybe();
  92. }
  93. /**
  94. * Execute The tested method on an object (a stub can be passed).
  95. * First argument is an object, the rest are supposed to be parameters passed to method.
  96. *
  97. * Example:
  98. *
  99. * ``` php
  100. * <?php
  101. * $I->wantTo('authenticate user');
  102. * $I->testMethod('User.authenticate');
  103. * $user = new User();
  104. * $I->executeTestedMethodOn($user, 'Davert','qwerty');
  105. * // This line $user->authenticate('Davert','qwerty') was called.
  106. * $I->seeResultEquals(true);
  107. * ?>
  108. * ```
  109. *
  110. * For static methods use 'executeTestedMethodWith'.
  111. *
  112. * @param $object
  113. * @see Unit::executeTestedMethodOn()
  114. *
  115. * ! This method is generated. DO NOT EDIT. !
  116. * ! Documentation taken from corresponding module !
  117. */
  118. public function executeTestedMethodOn($object) {
  119. $this->scenario->action('executeTestedMethodOn', func_get_args());
  120. if ($this->scenario->running()) {
  121. $result = $this->scenario->runStep();
  122. return new Maybe($result);
  123. }
  124. return new Maybe();
  125. }
  126. /**
  127. * Executes the tested static method with parameters provided.
  128. *
  129. * ```
  130. * <?php
  131. * $I->testMethod('User::validateName');
  132. * $I->executeTestedMethodWith('davert',true);
  133. * // This line User::validate('davert', true); was called
  134. * ?>
  135. * ```
  136. * For a non-static method use 'executeTestedMethodOn'
  137. *
  138. * @param $params
  139. * @throws \Codeception\Exception\Module
  140. * @see Unit::executeTestedMethodWith()
  141. *
  142. * ! This method is generated. DO NOT EDIT. !
  143. * ! Documentation taken from corresponding module !
  144. */
  145. public function executeTestedMethodWith($params) {
  146. $this->scenario->action('executeTestedMethodWith', func_get_args());
  147. if ($this->scenario->running()) {
  148. $result = $this->scenario->runStep();
  149. return new Maybe($result);
  150. }
  151. return new Maybe();
  152. }
  153. /**
  154. * Executes the method which is being tested.
  155. * If the method is not static, the class instance should be provided.
  156. *
  157. * If a method is static 'executeTestedWith' will be called.
  158. * If a method is not static 'executeTestedOn' will be called.
  159. * See those methods for the full reference
  160. *
  161. * @throws \InvalidArgumentException
  162. * @see Unit::executeTestedMethod()
  163. *
  164. * ! This method is generated. DO NOT EDIT. !
  165. * ! Documentation taken from corresponding module !
  166. */
  167. public function executeTestedMethod() {
  168. $this->scenario->action('executeTestedMethod', func_get_args());
  169. if ($this->scenario->running()) {
  170. $result = $this->scenario->runStep();
  171. return new Maybe($result);
  172. }
  173. return new Maybe();
  174. }
  175. /**
  176. * Executes a code block. The result of execution will be stored.
  177. * Parameter should be a valid Closure. The returned value can be checked with seeResult actions.
  178. *
  179. * Example:
  180. *
  181. * ``` php
  182. * <?php
  183. * $user = new User();
  184. * $I->execute(function() use ($user) {
  185. * $user->setName('Davert');
  186. * return $user->getName();
  187. * });
  188. * $I->seeResultEquals('Davert');
  189. * ?>
  190. * ```
  191. *
  192. * You can use native PHPUnit asserts in the executed code.
  193. * These can be either static methods of the 'PHPUnit_Framework_assert' class,
  194. * or functions taken from 'PHPUnit/Framework/Assert/Functions.php'. They start with 'assert_' prefix.
  195. * You should manually include this file, as these functions may conflict with functions in your code.
  196. *
  197. * Example:
  198. *
  199. * ``` php
  200. * <?php
  201. * require_once 'PHPUnit/Framework/Assert/Functions.php';
  202. *
  203. * $user = new User();
  204. * $I->execute(function() use ($user) {
  205. * $user->setName('Davert');
  206. * assertEquals('Davert', $user->getName());
  207. * });
  208. * ```
  209. *
  210. * @param \Closure $code
  211. * @see Unit::execute()
  212. *
  213. * ! This method is generated. DO NOT EDIT. !
  214. * ! Documentation taken from corresponding module !
  215. */
  216. public function execute($code) {
  217. $this->scenario->action('execute', func_get_args());
  218. if ($this->scenario->running()) {
  219. $result = $this->scenario->runStep();
  220. return new Maybe($result);
  221. }
  222. return new Maybe();
  223. }
  224. /**
  225. * Executes a method of an object.
  226. * Additional parameters can be provided.
  227. *
  228. * Example:
  229. *
  230. * ``` php
  231. * <?php
  232. * // to execute $user->getName()
  233. * $I->executeMethod($user,'getName');
  234. *
  235. * // to execute $user->setName('davert');
  236. * $I->executeMethod($user,'setName', 'davert');
  237. *
  238. * // or more parameters
  239. * $I->executeMethod($user, 'setNameAndAge', 'davert', '30');
  240. *
  241. * ?>
  242. * ```
  243. *
  244. * @param $object
  245. * @param $method
  246. * @see Unit::executeMethod()
  247. *
  248. * ! This method is generated. DO NOT EDIT. !
  249. * ! Documentation taken from corresponding module !
  250. */
  251. public function executeMethod($object, $method) {
  252. $this->scenario->action('executeMethod', func_get_args());
  253. if ($this->scenario->running()) {
  254. $result = $this->scenario->runStep();
  255. return new Maybe($result);
  256. }
  257. return new Maybe();
  258. }
  259. /**
  260. * Updates multiple properties of the selected object.
  261. * Can update even private and protected properties.
  262. *
  263. * Properties to be updated and their values are passed in the second parameter as an array:
  264. * array('theProperty' => 'some value',
  265. * ('anotherProperty' => 'another value')
  266. *
  267. * @param $obj
  268. * @param array $values
  269. * @see Unit::changeProperties()
  270. *
  271. * ! This method is generated. DO NOT EDIT. !
  272. * ! Documentation taken from corresponding module !
  273. */
  274. public function changeProperties($obj, $values = null) {
  275. $this->scenario->action('changeProperties', func_get_args());
  276. if ($this->scenario->running()) {
  277. $result = $this->scenario->runStep();
  278. return new Maybe($result);
  279. }
  280. return new Maybe();
  281. }
  282. /**
  283. * Updates a single property of the selected object
  284. * Can update even private and protected properties.
  285. *
  286. * @param $obj
  287. * @param $property
  288. * @param $value
  289. * @see Unit::changeProperty()
  290. *
  291. * ! This method is generated. DO NOT EDIT. !
  292. * ! Documentation taken from corresponding module !
  293. */
  294. public function changeProperty($obj, $property, $value) {
  295. $this->scenario->action('changeProperty', func_get_args());
  296. if ($this->scenario->running()) {
  297. $result = $this->scenario->runStep();
  298. return new Maybe($result);
  299. }
  300. return new Maybe();
  301. }
  302. /**
  303. *
  304. * @see Unit::seeExceptionThrown()
  305. *
  306. * ! This method is generated. DO NOT EDIT. !
  307. * ! Documentation taken from corresponding module !
  308. */
  309. public function seeExceptionThrown($classname, $message = null) {
  310. $this->scenario->assertion('seeExceptionThrown', func_get_args());
  311. if ($this->scenario->running()) {
  312. $result = $this->scenario->runStep();
  313. return new Maybe($result);
  314. }
  315. return new Maybe();
  316. }
  317. /**
  318. * Checks that a method of a stub was invoked after the last execution.
  319. * Requires a stub as the first parameter, the method name as the second.
  320. * Optionally pass the arguments which are expected by the executed method.
  321. *
  322. * Example:
  323. *
  324. * ``` php
  325. * <?php
  326. * $I->testMethod('UserService.create');
  327. * $I->haveStub($user = Stub::make('Model\User'));*
  328. * $service = new UserService($user);
  329. * $I->executeTestedMethodOn($service);
  330. * // we expect $user->save was invoked.
  331. * $I->seeMethodInvoked($user, 'save');
  332. * ?>
  333. * ```
  334. *
  335. * This method dynamically creates a mock from a stub.
  336. *
  337. * @magic
  338. * @see createMocks
  339. * @param $mock
  340. * @param $method
  341. * @param array $params
  342. * @see Unit::seeMethodInvoked()
  343. *
  344. * ! This method is generated. DO NOT EDIT. !
  345. * ! Documentation taken from corresponding module !
  346. */
  347. public function seeMethodInvoked($mock, $method, $params = null) {
  348. $this->scenario->assertion('seeMethodInvoked', func_get_args());
  349. if ($this->scenario->running()) {
  350. $result = $this->scenario->runStep();
  351. return new Maybe($result);
  352. }
  353. return new Maybe();
  354. }
  355. /**
  356. * Checks that a method of a stub was invoked *only once* after the last execution.
  357. * Requires a stub as the first parameter, a method name as the second.
  358. * Optionally pass the arguments which are expected by the executed method.
  359. *
  360. * Look for 'seeMethodInvoked' to see the example.
  361. * @magic
  362. * @see createMocks
  363. * @param $mock
  364. * @param $method
  365. * @param array $params
  366. * @see Unit::seeMethodInvokedOnce()
  367. *
  368. * ! This method is generated. DO NOT EDIT. !
  369. * ! Documentation taken from corresponding module !
  370. */
  371. public function seeMethodInvokedOnce($mock, $method, $params = null) {
  372. $this->scenario->assertion('seeMethodInvokedOnce', func_get_args());
  373. if ($this->scenario->running()) {
  374. $result = $this->scenario->runStep();
  375. return new Maybe($result);
  376. }
  377. return new Maybe();
  378. }
  379. /**
  380. * Checks that a method of a stub *was not invoked* after the last execution.
  381. * Requires a stub as the first parameter, a method name as the second.
  382. * Optionally pass the arguments which are expected by the executed method.
  383. * @magic
  384. * @see createMocks
  385. * @param $mock
  386. * @param $method
  387. * @param array $params
  388. * @see Unit::seeMethodNotInvoked()
  389. *
  390. * ! This method is generated. DO NOT EDIT. !
  391. * ! Documentation taken from corresponding module !
  392. */
  393. public function seeMethodNotInvoked($mock, $method, $params = null) {
  394. $this->scenario->assertion('seeMethodNotInvoked', func_get_args());
  395. if ($this->scenario->running()) {
  396. $result = $this->scenario->runStep();
  397. return new Maybe($result);
  398. }
  399. return new Maybe();
  400. }
  401. /**
  402. * Checks that a method of a stub was invoked *multiple times* after the last execution.
  403. * Requires a stub as the first parameter, a method name as the second and the expected number of executions.
  404. * Optionally pass the arguments which are expected by the executed method.
  405. *
  406. * Look for 'seeMethodInvoked' to see the example.
  407. * @magic
  408. * @see createMocks
  409. * @param $mock
  410. * @param $method
  411. * @param $times
  412. * @param array $params
  413. * @see Unit::seeMethodInvokedMultipleTimes()
  414. *
  415. * ! This method is generated. DO NOT EDIT. !
  416. * ! Documentation taken from corresponding module !
  417. */
  418. public function seeMethodInvokedMultipleTimes($mock, $method, $times, $params = null) {
  419. $this->scenario->assertion('seeMethodInvokedMultipleTimes', func_get_args());
  420. if ($this->scenario->running()) {
  421. $result = $this->scenario->runStep();
  422. return new Maybe($result);
  423. }
  424. return new Maybe();
  425. }
  426. /**
  427. * Asserts that the last result from the tested method is equal to value
  428. *
  429. * @param $value
  430. * @see Unit::seeResultEquals()
  431. *
  432. * ! This method is generated. DO NOT EDIT. !
  433. * ! Documentation taken from corresponding module !
  434. */
  435. public function seeResultEquals($value) {
  436. $this->scenario->assertion('seeResultEquals', func_get_args());
  437. if ($this->scenario->running()) {
  438. $result = $this->scenario->runStep();
  439. return new Maybe($result);
  440. }
  441. return new Maybe();
  442. }
  443. /**
  444. *
  445. * @see Unit::seeResultContains()
  446. *
  447. * ! This method is generated. DO NOT EDIT. !
  448. * ! Documentation taken from corresponding module !
  449. */
  450. public function seeResultContains($value) {
  451. $this->scenario->assertion('seeResultContains', func_get_args());
  452. if ($this->scenario->running()) {
  453. $result = $this->scenario->runStep();
  454. return new Maybe($result);
  455. }
  456. return new Maybe();
  457. }
  458. /**
  459. * Checks that the result of the last execution doesn't contain a value.
  460. *
  461. * @param $value
  462. * @see Unit::dontSeeResultContains()
  463. *
  464. * ! This method is generated. DO NOT EDIT. !
  465. * ! Documentation taken from corresponding module !
  466. */
  467. public function dontSeeResultContains($value) {
  468. $this->scenario->action('dontSeeResultContains', func_get_args());
  469. if ($this->scenario->running()) {
  470. $result = $this->scenario->runStep();
  471. return new Maybe($result);
  472. }
  473. return new Maybe();
  474. }
  475. /**
  476. * Checks that the result of the last execution is not equal to a value.
  477. *
  478. * @param $value
  479. * @see Unit::dontSeeResultEquals()
  480. *
  481. * ! This method is generated. DO NOT EDIT. !
  482. * ! Documentation taken from corresponding module !
  483. */
  484. public function dontSeeResultEquals($value) {
  485. $this->scenario->action('dontSeeResultEquals', func_get_args());
  486. if ($this->scenario->running()) {
  487. $result = $this->scenario->runStep();
  488. return new Maybe($result);
  489. }
  490. return new Maybe();
  491. }
  492. /**
  493. * Checks that the result of the last execution is empty.
  494. * @see Unit::seeEmptyResult()
  495. *
  496. * ! This method is generated. DO NOT EDIT. !
  497. * ! Documentation taken from corresponding module !
  498. */
  499. public function seeEmptyResult() {
  500. $this->scenario->assertion('seeEmptyResult', func_get_args());
  501. if ($this->scenario->running()) {
  502. $result = $this->scenario->runStep();
  503. return new Maybe($result);
  504. }
  505. return new Maybe();
  506. }
  507. /**
  508. * Checks that the result of the last execution is a specific type.
  509. * Either 'int', 'bool', 'string', 'array', 'float', 'null', 'resource', 'scalar' can be passed for simple types.
  510. * Otherwise the parameter must be a class and the result must be an instance of that class.
  511. *
  512. * Example:
  513. *
  514. * ``` php
  515. * <?php
  516. * $I->execute(function() { return new User });
  517. * $I->seeResultIs('User');
  518. * ?>
  519. * ```
  520. *
  521. * @param $type
  522. * @see Unit::seeResultIs()
  523. *
  524. * ! This method is generated. DO NOT EDIT. !
  525. * ! Documentation taken from corresponding module !
  526. */
  527. public function seeResultIs($type) {
  528. $this->scenario->assertion('seeResultIs', func_get_args());
  529. if ($this->scenario->running()) {
  530. $result = $this->scenario->runStep();
  531. return new Maybe($result);
  532. }
  533. return new Maybe();
  534. }
  535. /**
  536. * Checks that the property of an object equals the value provided.
  537. * Can check even protected or private properties.
  538. *
  539. * Bear in mind that testing non-public properties is not a good practice.
  540. * Use it only if you have no other way to test it.
  541. *
  542. * @param $object
  543. * @param $property
  544. * @param $value
  545. * @see Unit::seePropertyEquals()
  546. *
  547. * ! This method is generated. DO NOT EDIT. !
  548. * ! Documentation taken from corresponding module !
  549. */
  550. public function seePropertyEquals($object, $property, $value) {
  551. $this->scenario->assertion('seePropertyEquals', func_get_args());
  552. if ($this->scenario->running()) {
  553. $result = $this->scenario->runStep();
  554. return new Maybe($result);
  555. }
  556. return new Maybe();
  557. }
  558. /**
  559. * Checks that the property is a passed type.
  560. * Either 'int', 'bool', 'string', 'array', 'float', 'null', 'resource', 'scalar' can be passed for simple types.
  561. * Otherwise the parameter must be a class and the property must be an instance of that class.
  562. *
  563. * Bear in mind that testing non-public properties is not a good practice.
  564. * Use it only if you have no other way to test it.
  565. *
  566. * @param $object
  567. * @param $property
  568. * @param $type
  569. * @see Unit::seePropertyIs()
  570. *
  571. * ! This method is generated. DO NOT EDIT. !
  572. * ! Documentation taken from corresponding module !
  573. */
  574. public function seePropertyIs($object, $property, $type) {
  575. $this->scenario->assertion('seePropertyIs', func_get_args());
  576. if ($this->scenario->running()) {
  577. $result = $this->scenario->runStep();
  578. return new Maybe($result);
  579. }
  580. return new Maybe();
  581. }
  582. /**
  583. * Executes a method and checks that the result is equal to a value.
  584. * Good for testing values taken from getters.
  585. *
  586. * Example:
  587. *
  588. * ``` php
  589. * $I->testMethod('User.setName');
  590. * $user = new User();
  591. * $I->executeTestedMethodOn($user, 'davert');
  592. * $I->seeMethodReturns($user,'getName','davert');
  593. *
  594. * ```
  595. * *
  596. * @param $object
  597. * @param $method
  598. * @param $value
  599. * @param array $params
  600. * @see Unit::seeMethodReturns()
  601. *
  602. * ! This method is generated. DO NOT EDIT. !
  603. * ! Documentation taken from corresponding module !
  604. */
  605. public function seeMethodReturns($object, $method, $value, $params = null) {
  606. $this->scenario->assertion('seeMethodReturns', func_get_args());
  607. if ($this->scenario->running()) {
  608. $result = $this->scenario->runStep();
  609. return new Maybe($result);
  610. }
  611. return new Maybe();
  612. }
  613. /**
  614. * Executes a method and checks that the result is NOT equal to a value.
  615. * Good for testing values taken from getters.
  616. *
  617. * Look for 'seeMethodReturns' for example.
  618. *
  619. * @param $object
  620. * @param $method
  621. * @param $value
  622. * @param array $params
  623. * @see Unit::seeMethodNotReturns()
  624. *
  625. * ! This method is generated. DO NOT EDIT. !
  626. * ! Documentation taken from corresponding module !
  627. */
  628. public function seeMethodNotReturns($object, $method, $value, $params = null) {
  629. $this->scenario->assertion('seeMethodNotReturns', func_get_args());
  630. if ($this->scenario->running()) {
  631. $result = $this->scenario->runStep();
  632. return new Maybe($result);
  633. }
  634. return new Maybe();
  635. }
  636. /**
  637. *
  638. * @see EmulateModuleHelper::seeEquals()
  639. *
  640. * ! This method is generated. DO NOT EDIT. !
  641. * ! Documentation taken from corresponding module !
  642. */
  643. public function seeEquals($expected, $actual) {
  644. $this->scenario->assertion('seeEquals', func_get_args());
  645. if ($this->scenario->running()) {
  646. $result = $this->scenario->runStep();
  647. return new Maybe($result);
  648. }
  649. return new Maybe();
  650. }
  651. /**
  652. *
  653. * @see EmulateModuleHelper::seeFeaturesEquals()
  654. *
  655. * ! This method is generated. DO NOT EDIT. !
  656. * ! Documentation taken from corresponding module !
  657. */
  658. public function seeFeaturesEquals($expected) {
  659. $this->scenario->assertion('seeFeaturesEquals', func_get_args());
  660. if ($this->scenario->running()) {
  661. $result = $this->scenario->runStep();
  662. return new Maybe($result);
  663. }
  664. return new Maybe();
  665. }
  666. }