コード例 #1
0
 public function testRemoveObserver()
 {
     $weatherData = new WeatherData();
     $curCondDisplay = new CurrentConditionsDisplay($weatherData);
     // before any update from weatherData
     $expected = "CurrentConditionsDisplay: 0 F degrees and 0% humidity.";
     $this->assertEquals($expected, $curCondDisplay->display());
     // remove currentConditionsDisplay from Observers
     $weatherData->removeObserver($curCondDisplay);
     // change weatherData, so current conditions should change as well
     $weatherData->setMeasurements(5, 5, 5);
     // same message observer was not notified
     $this->assertEquals($expected, $curCondDisplay->display());
 }
コード例 #2
0
 public function testDisable()
 {
     $subject = new WeatherData();
     $display = new ThirdPartyDisplay($subject);
     $expected = "ThirdPartyDisplay: some data for temperature(0), pressure(0) and humidity(0).";
     $this->assertEquals($expected, $display->display());
     $subject->setMeasurements(80, 65, 35);
     $expected = "ThirdPartyDisplay: some data for temperature(80), pressure(65) and humidity(35).";
     $this->assertEquals($expected, $display->display());
     $display->disable();
     $subject->setMeasurements(10, 10, 10);
     $expected = "ThirdPartyDisplay: some data for temperature(80), pressure(65) and humidity(35).";
     $this->assertEquals($expected, $display->display());
 }