/**
  * @test
  */
 public function shouldBeCreatedFromMapping()
 {
     $source = (object) array('name' => 'foo', 'length' => 100, 'bytesCompleted' => 10);
     PropertyMapper::map($this->getFile(), $source);
     $this->assertEquals('foo', $this->getFile()->getName());
     $this->assertEquals(100, $this->getFile()->getSize());
     $this->assertEquals(10, $this->getFile()->getCompleted());
     $this->assertFalse($this->getFile()->isDone());
 }
 /**
  * @test
  */
 public function shouldBeCreatedFromMapping()
 {
     $source = (object) array('id' => 1, 'tier' => 1, 'scrape' => 'foo', 'announce' => 'bar');
     PropertyMapper::map($this->getTracker(), $source);
     $this->assertEquals(1, $this->getTracker()->getId());
     $this->assertEquals(1, $this->getTracker()->getTier());
     $this->assertEquals('foo', $this->getTracker()->getScrape());
     $this->assertEquals('bar', $this->getTracker()->getAnnounce());
 }
 /**
  * @test
  */
 public function shouldBeCreatedFromMapping()
 {
     $source = (object) array('host' => 'test', 'leecherCount' => 1, 'seederCount' => 2, 'lastScrapeResult' => 'foo', 'lastAnnounceResult' => 'bar');
     PropertyMapper::map($this->getTrackerStats(), $source);
     $this->assertEquals('test', $this->getTrackerStats()->getHost());
     $this->assertEquals(1, $this->getTrackerStats()->getLeecherCount());
     $this->assertEquals(2, $this->getTrackerStats()->getSeederCount());
     $this->assertEquals('foo', $this->getTrackerStats()->getLastScrapeResult());
     $this->assertEquals('bar', $this->getTrackerStats()->getLastAnnounceResult());
 }
 /**
  * @test
  */
 public function shouldSave()
 {
     $expected = array('alt-speed-down' => 1, 'alt-speed-enabled' => true, 'download-dir' => 'foo', 'download-queue-enabled' => true, 'download-queue-size' => 5, 'incomplete-dir' => 'bar', 'incomplete-dir-enabled' => true, 'script-torrent-done-filename' => 'baz', 'script-torrent-done-enabled' => true, 'seedRatioLimit' => 3.14, 'seedRatioLimited' => true, 'seed-queue-size' => 5, 'seed-queue-enabled' => true, 'speed-limit-down' => 100, 'speed-limit-down-enabled' => true, 'speed-limit-up' => 100, 'speed-limit-up-enabled' => true);
     PropertyMapper::map($this->getSession(), (object) $expected);
     $client = $this->createMock('Transmission\\Client');
     $client->expects($this->once())->method('call')->with('session-set', $expected)->will($this->returnCallback(function () {
         return (object) array('result' => 'success');
     }));
     $this->getSession()->setClient($client);
     $this->getSession()->save();
 }
 /**
  * @test
  */
 public function shouldBeCreatedFromMapping()
 {
     $source = (object) array('id' => 1, 'eta' => 10, 'sizeWhenDone' => 10000, 'name' => 'foo', 'hashString' => 'bar', 'status' => 0, 'isFinished' => false, 'rateUpload' => 10, 'rateDownload' => 100, 'files' => array((object) array()), 'peers' => array((object) array(), (object) array()), 'trackers' => array((object) array(), (object) array(), (object) array()));
     PropertyMapper::map($this->getTorrent(), $source);
     $this->assertEquals(1, $this->getTorrent()->getId());
     $this->assertEquals(10, $this->getTorrent()->getEta());
     $this->assertEquals(10000, $this->getTorrent()->getSize());
     $this->assertEquals('foo', $this->getTorrent()->getName());
     $this->assertEquals('bar', $this->getTorrent()->getHash());
     $this->assertEquals(0, $this->getTorrent()->getStatus());
     $this->assertFalse($this->getTorrent()->isFinished());
     $this->assertEquals(10, $this->getTorrent()->getUploadRate());
     $this->assertEquals(100, $this->getTorrent()->getDownloadRate());
     $this->assertCount(1, $this->getTorrent()->getFiles());
     $this->assertCount(2, $this->getTorrent()->getPeers());
     $this->assertCount(3, $this->getTorrent()->getTrackers());
 }
 /**
  * @test
  */
 public function shouldBeCreatedFromMapping()
 {
     $source = (object) array('address' => 'foo', 'clientName' => 'foo', 'clientIsChoked' => false, 'clientIsInterested' => true, 'flagStr' => 'foo', 'isDownloadingFrom' => false, 'isEncrypted' => true, 'isIncoming' => false, 'isUploadingTo' => true, 'isUTP' => false, 'peerIsChoked' => true, 'peerIsInterested' => false, 'port' => 3000, 'progress' => 10.5, 'rateToClient' => 1000, 'rateFromClient' => 10000);
     PropertyMapper::map($this->getPeer(), $source);
     $this->assertEquals('foo', $this->getPeer()->getAddress());
     $this->assertEquals('foo', $this->getPeer()->getClientName());
     $this->assertFalse($this->getPeer()->isClientChoked());
     $this->assertTrue($this->getPeer()->isClientInterested());
     $this->assertFalse($this->getPeer()->isDownloading());
     $this->assertTrue($this->getPeer()->isEncrypted());
     $this->assertFalse($this->getPeer()->isIncoming());
     $this->assertTrue($this->getPeer()->isUploading());
     $this->assertFalse($this->getPeer()->isUtp());
     $this->assertTrue($this->getPeer()->isPeerChoked());
     $this->assertFalse($this->getPeer()->isPeerInterested());
     $this->assertEquals(3000, $this->getPeer()->getPort());
     $this->assertEquals(10.5, $this->getPeer()->getProgress());
     $this->assertEquals(1000, $this->getPeer()->getUploadRate());
     $this->assertEquals(10000, $this->getPeer()->getDownloadRate());
 }
 /**
  * @param array $trackers
  */
 public function setTrackers(array $trackers)
 {
     $this->trackers = array_map(function ($tracker) {
         return PropertyMapper::map(new Tracker(), $tracker);
     }, $trackers);
 }
 private static function map($object, $class)
 {
     return PropertyMapper::map(new $class(), $object);
 }