]> git.agnieray.net Git - galette.git/blob - tests/Galette/Repository/tests/units/PaymentTypes.php
Check MySQL warning in tests suite
[galette.git] / tests / Galette / Repository / tests / units / PaymentTypes.php
1 <?php
2
3 /* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
4
5 /**
6 * Payment types repository tests
7 *
8 * PHP version 5
9 *
10 * Copyright © 2019 The Galette Team
11 *
12 * This file is part of Galette (http://galette.tuxfamily.org).
13 *
14 * Galette is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
18 *
19 * Galette is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with Galette. If not, see <http://www.gnu.org/licenses/>.
26 *
27 * @category Repository
28 * @package GaletteTests
29 *
30 * @author Johan Cwiklinski <johan@x-tnd.be>
31 * @copyright 2019 The Galette Team
32 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
33 * @version SVN: $Id$
34 * @link http://galette.tuxfamily.org
35 * @since 2019-12-17
36 */
37
38 namespace Galette\Repository\test\units;
39
40 use Galette\GaletteTestCase;
41
42 /**
43 * Payment types repository tests
44 *
45 * @category Repository
46 * @name PaymentTypes
47 * @package GaletteTests
48 * @author Johan Cwiklinski <johan@x-tnd.be>
49 * @copyright 2019 The Galette Team
50 * @license http://www.gnu.org/licenses/gpl-3.0.html GPL License 3.0 or (at your option) any later version
51 * @link http://galette.tuxfamily.org
52 * @since 2019-12-17
53 */
54 class PaymentTypes extends GaletteTestCase
55 {
56 private $remove = [];
57
58 /**
59 * Set up tests
60 *
61 * @param string $method Calling method
62 *
63 * @return void
64 */
65 public function beforeTestMethod($method)
66 {
67 parent::beforeTestMethod($method);
68
69 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
70 $res = $types->installInit(false);
71 $this->boolean($res)->isTrue();
72 }
73
74 /**
75 * Tear down tests
76 *
77 * @param string $method Calling method
78 *
79 * @return void
80 */
81 public function afterTestMethod($method)
82 {
83 parent::afterTestMethod($method);
84 $this->deletePaymentType();
85 }
86
87 /**
88 * Delete payment type
89 *
90 * @return void
91 */
92 private function deletePaymentType()
93 {
94 if (is_array($this->remove) && count($this->remove) > 0) {
95 $delete = $this->zdb->delete(\Galette\Entity\PaymentType::TABLE);
96 $delete->where->in(\Galette\Repository\PaymentTypes::PK, $this->remove);
97 $this->zdb->execute($delete);
98 }
99
100 //Clean logs
101 $this->zdb->db->query(
102 'TRUNCATE TABLE ' . PREFIX_DB . \Galette\Core\History::TABLE,
103 \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE
104 );
105 }
106
107 /**
108 * Test getList
109 *
110 * @return void
111 */
112 public function testGetList()
113 {
114 $types = new \Galette\Repository\PaymentTypes($this->zdb, $this->preferences, $this->login);
115
116 $list = $types->getList();
117 $this->array($list)->hasSize(6);
118
119 if ($this->zdb->isPostgres()) {
120 $select = $this->zdb->select(\Galette\Entity\PaymentType::TABLE . '_id_seq');
121 $select->columns(['last_value']);
122 $results = $this->zdb->execute($select);
123 $result = $results->current();
124 $this->integer($result->last_value)->isGreaterThanOrEqualTo(6, 'Incorrect payments types sequence');
125 }
126
127 //reinstall payment types
128 $types->installInit();
129
130 $list = $types->getList();
131 $this->array($list)->hasSize(6);
132
133 if ($this->zdb->isPostgres()) {
134 $select = $this->zdb->select(\Galette\Entity\PaymentType::TABLE . '_id_seq');
135 $select->columns(['last_value']);
136 $results = $this->zdb->execute($select);
137 $result = $results->current();
138 $this->integer($result->last_value)->isGreaterThanOrEqualTo(
139 6,
140 'Incorrect payment types sequence ' . $result->last_value
141 );
142 }
143 }
144 }