Skip to content

Commit 4cc3b0a

Browse files
committed
Created tests!
1 parent 843e2df commit 4cc3b0a

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
"require": {
55
"illuminate/support": "~5.0"
66
},
7+
"require-dev": {
8+
"phpunit/phpunit": "4.5.*"
9+
},
710
"autoload": {
811
"psr-4": {
912
"Dowilcox\\": "src/"

phpunit.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit backupGlobals="false"
3+
backupStaticAttributes="false"
4+
bootstrap="vendor/autoload.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
processIsolation="false"
10+
stopOnFailure="false"
11+
syntaxCheck="false"
12+
>
13+
<testsuites>
14+
<testsuite name="Package Test Suite">
15+
<directory suffix=".php">./tests/</directory>
16+
</testsuite>
17+
</testsuites>
18+
</phpunit>

tests/JsVarTest.php

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?php
2+
3+
class JsVarTest extends PHPUnit_Framework_TestCase
4+
{
5+
protected $jsVar;
6+
7+
public function setup()
8+
{
9+
$this->jsVar = new \Dowilcox\JsVar\JsVar('tests');
10+
}
11+
12+
/** @test */
13+
public function it_outputs_array()
14+
{
15+
$this->assertEquals([], $this->jsVar->toArray());
16+
}
17+
18+
/** @test */
19+
public function it_outputs_json()
20+
{
21+
$this->assertEquals('[]', $this->jsVar->toJson());
22+
}
23+
24+
/** @test */
25+
public function it_adds_new_key_value_pair()
26+
{
27+
$this->assertEquals(['user' => 'test'], $this->jsVar->add('user', 'test')->toArray());
28+
}
29+
30+
/** @test */
31+
public function it_dumps_to_javascript()
32+
{
33+
$this->jsVar->add('user', 'test');
34+
$this->assertEquals('window.tests = window.tests || {"user":"test"};', $this->jsVar->dump());
35+
}
36+
37+
/** @test */
38+
public function it_removes_key_value_pair()
39+
{
40+
$this->jsVar->add('user', 'test');
41+
$this->assertEquals([], $this->jsVar->remove('user')->toArray());
42+
}
43+
}

0 commit comments

Comments
 (0)