1<?php 2 3/* Copyright (c) 2019 Richard Klees <richard.klees@concepts-and-training.de> Extended GPL, see docs/LICENSE */ 4 5use PHPUnit\Framework\TestCase; 6 7use ILIAS\Setup\Environment; 8use ILIAS\Setup\Objective; 9 10class Test_ilDatabaseUpdateStep extends ilDatabaseUpdateSteps 11{ 12 public function step_1(\ilDBInterface $db) 13 { 14 } 15} 16 17class ilDatabaseUpdateStepTest extends TestCase 18{ 19 protected function setUp() : void 20 { 21 $this->parent = $this->createMock(Test_ilDatabaseUpdateStep::class); 22 $this->precondition = $this->createMock(Objective::class); 23 24 $this->step = new \ilDatabaseUpdateStep( 25 $this->parent, 26 1, 27 $this->precondition, 28 $this->precondition 29 ); 30 } 31 32 public function testGetPreconditions() 33 { 34 $env = $this->createMock(Environment::class); 35 36 $this->assertEquals( 37 [$this->precondition, $this->precondition], 38 $this->step->getPreconditions($env) 39 ); 40 } 41 42 public function testCallsExecutionLog() 43 { 44 $env = $this->createMock(Environment::class); 45 $log = $this->createMock(\ilDatabaseUpdateStepExecutionLog::class); 46 $db = $this->createMock(\ilDBInterface::class); 47 48 $env 49 ->method("getResource") 50 ->will($this->returnValueMap([ 51 [Environment::RESOURCE_DATABASE, $db], 52 [\ilDatabaseUpdateStepExecutionLog::class, $log] 53 ])); 54 55 $log 56 ->expects($this->once(), $this->at(0)) 57 ->method("started") 58 ->with(get_class($this->parent), 1); 59 60 $log 61 ->expects($this->once(), $this->at(1)) 62 ->method("finished") 63 ->with(get_class($this->parent), 1); 64 65 $this->step->achieve($env); 66 } 67 68 public function testCallsMethod() 69 { 70 $env = $this->createMock(Environment::class); 71 $db = $this->createMock(\ilDBInterface::class); 72 73 $env 74 ->method("getResource") 75 ->will($this->returnValueMap([ 76 [Environment::RESOURCE_DATABASE, $db], 77 [\ilDatabaseUpdateStepExecutionLog::class, null] 78 ])); 79 80 $this->parent 81 ->expects($this->once()) 82 ->method("step_1") 83 ->with($db) 84 ->willReturn($null); 85 86 $this->step->achieve($env); 87 } 88} 89