Proyectos de Subversion Moodle

Rev

Rev 11 | Mostrar el archivo completo | | | Autoría | Ultima modificación | Ver Log |

Rev 11 Rev 1441
Línea 14... Línea 14...
14
// You should have received a copy of the GNU General Public License
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
Línea 16... Línea 16...
16
 
16
 
Línea -... Línea 17...
-
 
17
namespace core;
-
 
18
 
17
namespace core;
19
use core\exception\coding_exception;
18
 
20
 
19
/**
21
/**
20
 * Unit tests for our locking implementations.
22
 * Unit tests for our locking implementations.
21
 *
23
 *
22
 * @package    core
24
 * @package    core
23
 * @category   test
25
 * @category   test
-
 
26
 * @copyright  2013 Damyon Wiese
-
 
27
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
-
 
28
 * @covers \core\lock\db_record_lock_factory
24
 * @copyright  2013 Damyon Wiese
29
 * @covers \core\lock\file_lock_factory
25
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
30
 * @covers \core\lock\lock
Línea 26... Línea 31...
26
 */
31
 */
27
class lock_test extends \advanced_testcase {
32
final class lock_test extends \advanced_testcase {
28
 
33
 
29
    /**
34
    /**
-
 
35
     * Some lock types will store data in the database.
30
     * Some lock types will store data in the database.
36
     */
31
     */
37
    protected function setUp(): void {
Línea 32... Línea 38...
32
    protected function setUp(): void {
38
        parent::setUp();
33
        $this->resetAfterTest(true);
39
        $this->resetAfterTest(true);
34
    }
40
    }
35
 
41
 
36
    /**
42
    /**
37
     * Run a suite of tests on a lock factory class.
43
     * Run a suite of tests on a lock factory class.
Línea 38... Línea 44...
38
     *
44
     *
39
     * @param class $lockfactoryclass - A lock factory class to test
45
     * @param string $lockfactoryclass - name of a lock factory class to test.
Línea 40... Línea 46...
40
     */
46
     */
Línea 124... Línea 130...
124
        $this->run_on_lock_factory(\core\lock\lock_config::get_lock_factory_class());
130
        $this->run_on_lock_factory(\core\lock\lock_config::get_lock_factory_class());
Línea 125... Línea 131...
125
 
131
 
126
        // Manually create the core no-configuration factories.
132
        // Manually create the core no-configuration factories.
127
        $this->run_on_lock_factory(\core\lock\db_record_lock_factory::class);
133
        $this->run_on_lock_factory(\core\lock\db_record_lock_factory::class);
128
        $this->run_on_lock_factory(\core\lock\file_lock_factory::class);
-
 
129
 
134
        $this->run_on_lock_factory(\core\lock\file_lock_factory::class);
Línea -... Línea 135...
-
 
135
    }
-
 
136
 
-
 
137
    public function test_exception_for_unreleased_locks(): void {
-
 
138
        $factory = new \core\lock\db_record_lock_factory('mod_assign');
-
 
139
        $lock = $factory->get_lock('abc', 0);
-
 
140
 
-
 
141
        // Using try/catch, not expectException, because I want to verify a few things.
-
 
142
        try {
-
 
143
            $lock->release_if_not_released(true);
-
 
144
        } catch (coding_exception $e) {
-
 
145
            $this->assertStringContainsString('A lock was created but not released at:', $e->getMessage());
-
 
146
            $this->assertStringContainsString('call to core\lock\db_record_lock_factory->get_lock()', $e->getMessage());
-
 
147
            $this->assertStringContainsString('call to core\lock_test->test_exception_for_unreleased_locks()', $e->getMessage());
-
 
148
            return;
-
 
149
        }
-
 
150
 
-
 
151
        // Now use expectException to get the standard failure message.
130
    }
152
        $this->expectException(coding_exception::class);