Beispiel #1
0
 /**
  * Make sure that we can unregister a subject.
  */
 public function testOffsetUnset()
 {
     $subject = new Subject();
     Property::set($this->collection, 'subjects', array('test' => $subject));
     unset($this->collection['test']);
     unset($this->collection['test']);
     // should not thrown an exception
     $this->assertSame(array(), Property::get($this->collection, 'subjects'), 'Make sure the "test" subject is unregistered.');
 }
Beispiel #2
0
 /**
  * {@inheritDoc}
  */
 public function receiveUpdate(SubjectInterface $subject)
 {
     $this->order = self::$counter++;
     $this->subject = $subject;
     if ($this->double) {
         $subject->notifyObservers();
     }
     if ($this->test) {
         $this->test->assertTrue(Property::get($subject, 'updating'), 'The subject should be updating.');
     }
     if ($this->interrupt) {
         $this->reason = new ReasonException('Testing interruption.');
         $subject->interruptUpdate($this->reason);
     }
 }
Beispiel #3
0
 /**
  * Make sure that we can unregister a single occurrences of an observer.
  */
 public function testUnregisterObserver()
 {
     $observers = array(new Observer(), new Observer(), new Observer());
     Property::set($this->subject, 'observers', array(456 => array($observers[2], $observers[2]), 0 => array($observers[0], $observers[1]), 123 => array($observers[0], $observers[1], $observers[2], $observers[1])));
     $this->subject->unregisterObserver($observers[0]);
     $this->assertSame(array(0 => array(1 => $observers[1]), 123 => array($observers[0], $observers[1], $observers[2], $observers[1]), 456 => array($observers[2], $observers[2])), Property::get($this->subject, 'observers'), 'Unregister the first occurrence sorted by priority.');
     $this->subject->unregisterObserver($observers[2], 456);
     $this->assertSame(array(0 => array(1 => $observers[1]), 123 => array($observers[0], $observers[1], $observers[2], $observers[1]), 456 => array(1 => $observers[2])), Property::get($this->subject, 'observers'), 'Unregister the first occurrence for a specific priority.');
 }
Beispiel #4
0
 /**
  * Make sure that we can unregister a subject.
  */
 public function testUnregisterSubject()
 {
     Property::set($this->collection, 'subjects', array('test' => new Subject()));
     $this->collection->unregisterSubject('test');
     $this->assertSame(array(), Property::get($this->collection, 'subjects'), 'Make sure the "test" subject is unregistered.');
 }