Skip to content

Commit

Permalink
Add method to fetch all card data objects
Browse files Browse the repository at this point in the history
Add new getCards() method to load all cards, instead of relying on
getCardAtIndex() all the time.
  • Loading branch information
wadmiraal committed Jun 1, 2016
1 parent 26c4b01 commit d171336
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/VCardParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,17 @@ public function __construct($content)
$this->parse();
}

/**
* Fetch all the imported VCards.
*
* @return array
* A list of VCard card data objects.
*/
public function getCards()
{
return $this->vcardObjects;
}

/**
* Fetch the imported VCard at the specified index.
*
Expand Down
8 changes: 5 additions & 3 deletions tests/VCardParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ public function testVcardDB()
public function testFromFile()
{
$parser = VCardParser::parseFromFile(__DIR__ . '/example.vcf');
$this->assertEquals($parser->getCardAtIndex(0)->firstname, "Wouter");
$this->assertEquals($parser->getCardAtIndex(0)->lastname, "Admiraal");
$this->assertEquals($parser->getCardAtIndex(0)->fullname, "Wouter Admiraal");
// Use this opportunity to test fetching all cards directly.
$cards = $parser->getCards();
$this->assertEquals($cards[0]->firstname, "Wouter");
$this->assertEquals($cards[0]->lastname, "Admiraal");
$this->assertEquals($cards[0]->fullname, "Wouter Admiraal");
}

/**
Expand Down

0 comments on commit d171336

Please sign in to comment.