public function testGetMetrics() { $diObj = new DI(); $expectedMetric = new Metric(); $expectedMetric->setName('DiskUsage'); $expectedMetric->setUnit('Percent'); $expectedMetric->setValue('56'); $expectedMetric->setNamespace('CustomMetric/Test'); $fakeCmdRunner = Stub::make('\\AWSCustomMetric\\CommandRunner', ['execute' => function () { }, 'getReturnCode' => 0, 'getReturnValue' => Stub::consecutive('Darwin', '56')]); $diObj->setCommandRunner($fakeCmdRunner); $diskUsage = new DiskUsage($diObj, 'CustomMetric/Test'); $returnArray = $diskUsage->getMetrics(); $this->assertCount(1, $returnArray, 'Disk usage return array failed'); $this->assertEquals($expectedMetric, $returnArray[0], 'DiskUsage return metric object failed!'); $fakeCmdRunner = Stub::make('\\AWSCustomMetric\\CommandRunner', ['execute' => function () { }, 'getReturnCode' => 0, 'getReturnValue' => Stub::consecutive('Linux', '0')]); $diObj->setCommandRunner($fakeCmdRunner); $diskUsage = new DiskUsage($diObj, 'CustomMetric/Test'); $returnArray = $diskUsage->getMetrics(); $this->assertNull($returnArray, 'DiskUsage return null failed!'); }
public function testConsecutive() { $dummy = Stub::make('DummyClass', array('helloWorld' => Stub::consecutive('david', 'emma', 'sam', 'amy'))); $this->assertEquals('david', $dummy->helloWorld()); $this->assertEquals('emma', $dummy->helloWorld()); $this->assertEquals('sam', $dummy->helloWorld()); $this->assertEquals('amy', $dummy->helloWorld()); // Expected null value when no more values $this->assertNull($dummy->helloWorld()); }
public function testValidateNotAllowEmpty() { $validation = Stub::make('Phalcon\\Validation', array('getValue' => Stub::consecutive('', 'val2'), 'appendMessage' => true)); $validator = new ConfirmationOf(array('origField' => 'original', 'allowEmpty' => false)); $this->assertFalse($validator->validate($validation, 'confirmation')); }