Skip to content

Commit

Permalink
remove Yii2 requirements when used as standalone
Browse files Browse the repository at this point in the history
  • Loading branch information
tonydspaniard committed Aug 25, 2017
1 parent d79547c commit 6ffc3f7
Showing 7 changed files with 37 additions and 22 deletions.
17 changes: 17 additions & 0 deletions src/Exception/InvalidConfigException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

/*
* This file is part of the 2amigos/yii2-qrcode-helper project.
*
* (c) 2amigOS! <http://2amigos.us/>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/

namespace Da\QrCode\Exception;

class InvalidConfigException extends Exception
{

}
4 changes: 2 additions & 2 deletions src/Format/BookMarkFormat.php
Original file line number Diff line number Diff line change
@@ -11,8 +11,8 @@

namespace Da\QrCode\Format;

use Da\QrCode\Exception\InvalidConfigException;
use Da\QrCode\Traits\UrlTrait;
use yii\base\InvalidConfigException;

/**
* Class BookMark formats a string to properly create a Bookmark QrCode
@@ -33,7 +33,7 @@ class BookMarkFormat extends AbstractFormat

/**
* @inheritdoc
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException
*/
public function init()
{
2 changes: 1 addition & 1 deletion src/Format/WifiFormat.php
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@

namespace Da\QrCode\Format;

use yii\base\InvalidConfigException;
use Da\QrCode\Exception\InvalidConfigException;

/**
* Class Wifi formats a string to properly create a Wifi QrCode
2 changes: 1 addition & 1 deletion src/Format/vCardFormat.php
Original file line number Diff line number Diff line change
@@ -11,9 +11,9 @@

namespace Da\QrCode\Format;

use Da\QrCode\Exception\InvalidConfigException;
use Da\QrCode\Traits\EmailTrait;
use Da\QrCode\Traits\UrlTrait;
use yii\base\InvalidConfigException;

/**
* Class vCard creates a valid vCard 4.0 QrCode string
9 changes: 4 additions & 5 deletions src/Traits/EmailTrait.php
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@

namespace Da\QrCode\Traits;

use yii\base\InvalidConfigException;
use yii\validators\EmailValidator;
use Da\QrCode\Exception\InvalidConfigException;

/**
* EmailTrait
@@ -39,9 +38,9 @@ trait EmailTrait
public function setEmail($value)
{
$error = null;
$validator = new EmailValidator();
if (!$validator->validate($value, $error)) {
throw new InvalidConfigException($error);

if (!filter_var($value, FILTER_VALIDATE_EMAIL)) {
throw new InvalidConfigException('Email seems incorrect.');
}

$this->email = $value;
9 changes: 4 additions & 5 deletions src/Traits/UrlTrait.php
Original file line number Diff line number Diff line change
@@ -11,8 +11,7 @@

namespace Da\QrCode\Traits;

use yii\base\InvalidConfigException;
use yii\validators\UrlValidator;
use Da\QrCode\Exception\InvalidConfigException;

trait UrlTrait
{
@@ -29,9 +28,9 @@ trait UrlTrait
public function setUrl($value)
{
$error = null;
$validator = new UrlValidator();
if (!$validator->validate($value, $error)) {
throw new InvalidConfigException($error);

if (!filter_var($value, FILTER_VALIDATE_URL)) {
throw new InvalidConfigException('Url seems invalid.');
}

$this->url = $value;
16 changes: 8 additions & 8 deletions tests/FormatsTest.php
Original file line number Diff line number Diff line change
@@ -35,13 +35,13 @@ public function testBookMark()
$this->assertEquals("http://2amigos.us", $bookmark->getUrl());
// using __toString()
$this->assertEquals("MEBKM:TITLE:test-title;URL:http://2amigos.us;;", $bookmark);
$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$bookmark->url = 'wrong!url';
}

public function testBookMarkFailed()
{
$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$bookmark = new BookMarkFormat();
}

@@ -57,7 +57,7 @@ public function testMailMessage()
$this->assertEquals("hola@2amigos.us", $message->getEmail());
$this->assertEquals("MATMSG:TO:hola@2amigos.us;SUB:test;BODY:test-body;;", $message->getText());

$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$message = new MailMessageFormat(['email' => 'wrongaddress!!']);

}
@@ -71,7 +71,7 @@ public function testMailTo()

public function testMailToWrongEmail()
{
$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$mailTo = new MailToFormat(['email' => 'wrongaddress-@...']);
}

@@ -94,7 +94,7 @@ public function testMeCard()
"NOTE:test-note;\nBDAY:19711201;\nADR:test-address;\nURL:http://2amigos.us;\nNICKNAME:tonydspaniard;\n;";
$this->assertEquals($expected, $card->getText());

$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$card->email = 'wrongaddress!!!';
$card->getText();

@@ -152,7 +152,7 @@ public function testVCard()

$this->assertEquals($expected, $vcard->getText());

$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$vcard->email = "wrongaddress";

}
@@ -175,7 +175,7 @@ public function testVCardPhoto()

$vcard->photo = 'wrongimage.superb';

$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$method->invoke($vcard);
}

@@ -185,7 +185,7 @@ public function testWifi()
$this->assertEquals("WIFI:T:WPA;S:testSSID;P:HAKUNAMATATA;;", $wifi->getText());
$wifi->hidden = 'true';
$this->assertEquals("WIFI:T:WPA;S:testSSID;P:HAKUNAMATATA;H:true;", $wifi->getText());
$this->expectException('yii\base\InvalidConfigException');
$this->expectException('Da\QrCode\Exception\InvalidConfigException');
$wifi = new WifiFormat(['authentication' => 'WPA', 'password' => 'HAKUNAMATATA']);
}

0 comments on commit 6ffc3f7

Please sign in to comment.