Skip to content

Commit b837c8f

Browse files
committed
updated read me.md with test cases
1 parent f0bd1e4 commit b837c8f

File tree

3 files changed

+150
-70
lines changed

3 files changed

+150
-70
lines changed

.idea/workspace.xml

Lines changed: 54 additions & 49 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/jai/Contact/composer.json

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
"require": {},
1212
"require-dev": {
1313
"phpunit/phpunit": "4.8.*"
14-
},
15-
"autoload-dev": {
16-
"classmap": [
17-
"tests/testPackageCase.php"
18-
]
1914
}
15+
2016
}

readme.md

Lines changed: 95 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,106 @@
1-
# Laravel PHP Framework
1+
## Laravel 5 package Development from scratch
22

3-
[![Build Status](https://travis-ci.org/laravel/framework.svg)](https://travis-ci.org/laravel/framework)
4-
[![Total Downloads](https://poser.pugx.org/laravel/framework/d/total.svg)](https://packagist.org/packages/laravel/framework)
5-
[![Latest Stable Version](https://poser.pugx.org/laravel/framework/v/stable.svg)](https://packagist.org/packages/laravel/framework)
6-
[![Latest Unstable Version](https://poser.pugx.org/laravel/framework/v/unstable.svg)](https://packagist.org/packages/laravel/framework)
7-
[![License](https://poser.pugx.org/laravel/framework/license.svg)](https://packagist.org/packages/laravel/framework)
3+
Trying to explain Laravel specific package development in Laravel 5 :+1:
84

9-
Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable, creative experience to be truly fulfilling. Laravel attempts to take the pain out of development by easing common tasks used in the majority of web projects, such as authentication, routing, sessions, queueing, and caching.
5+
With the new Laravel 5 - `php artisan workbench` is made redundant.
6+
And technically Laravel packages should not be tightly coupled with Laravel core, so that make sense.
107

11-
Laravel is accessible, yet powerful, providing tools needed for large, robust applications. A superb inversion of control container, expressive migration system, and tightly integrated unit testing support give you the tools you need to build any application with which you are tasked.
8+
But for some who wants to build Laravel specific packages I suppose this will help them to have a quick start.
129

13-
## Official Documentation
10+
### Step 1 : Install Laravel
1411

15-
Documentation for the framework can be found on the [Laravel website](http://laravel.com/docs).
12+
http://laravel.com/docs/5.0#install-laravel
1613

17-
## Contributing
14+
Note : In my above root i haven't added a .env file. You need to configure this.
15+
Note : Laravel may require some permissions to be configured: folders within storage and vendor require write access by the web server.
1816

19-
Thank you for considering contributing to the Laravel framework! The contribution guide can be found in the [Laravel documentation](http://laravel.com/docs/contributions).
17+
#### Step 2 : Create package folder and service provider
18+
19+
In root directory create a folder called `packages/vendorName/packageName/src`
20+
e.g. `root/packages/jai/Contact/src`
21+
22+
Now navigate to the `src` folder and create a file for your service provider, e.g. `ContactServiceprovider.php`.
23+
24+
Your service provider should extend ServiceProvider and has to implement the `register` method.
25+
26+
Please look into this [file](https://github.com/jaiwalker/Develop-laravel5-package-/blob/master/packages/jai/Contact/src/ContactServiceprovider.php) for an example.
27+
28+
*If you want you can write `dd("testing");` in the boot function and go to step 3, but if you have copied the service provider file you might want to create views, routes, config and controllers.*
29+
30+
#### Creating Routes
31+
32+
In your `src` folder create a new `Http` folder in which you create your `routes.php` file.
33+
([example file](https://github.com/jaiwalker/Develop-laravel5-package-/blob/master/packages/jai/Contact/src/Http/routes.php))
34+
35+
#### Creating Controllers
36+
37+
In your `Http` folder create a new directory called `Controllers`. In this folder you can create your controllers.
38+
([example file](https://github.com/jaiwalker/Develop-laravel5-package-/blob/master/packages/jai/Contact/src/Http/Controllers/ContactController.php))
39+
40+
#### Creating Config
41+
42+
In your `src` folder create a new directory and call it `config`. In it create a new file (e.g. `contact.php`) like this [file](https://github.com/jaiwalker/Develop-laravel5-package-/blob/master/packages/jai/Contact/src/config/contact.php)
43+
44+
Note: if you want to access config - you need to publish first - after doing step 5 you can run `php artisan vendor:publish`. This will push you config file (contact.php => project/config/contact.php) and then you can access config.
45+
46+
#### Creating Views
47+
48+
This is a bit different, in your package folder (e.g. `jai/Contact`) create a new folder call `views`.
49+
([example file 1](https://github.com/jaiwalker/Develop-laravel5-package-/blob/master/packages/jai/Contact/views/contact.blade.php) [example file 2](https://github.com/jaiwalker/Develop-laravel5-package-/blob/master/packages/jai/Contact/views/template.blade.php))
50+
51+
### Step 3: Add package path in root composer.json
52+
53+
In your root composer.json file `"jai\\Contact\\": "packages/jai/Contact/src/"` under psr-4
54+
55+
```
56+
"psr-4": {
57+
"App\\": "app/",
58+
"Jai\\Contact\\": "packages/jai/contact/src/",
59+
}
60+
```
61+
62+
### Step 4: add service provider in app conifg.
63+
64+
In your `root/config/app.php` under `providers` add your package service provider to hook your package in.
65+
66+
```
67+
'Jai\Contact\ContactServiceProvider',
68+
```
69+
70+
### Step 5: loading your package
71+
run `composer dump-autoload` - make sure there are no errors.
72+
73+
all done - now you can access your package via url - "yourwebsite/contact"
74+
75+
## Update Included testing
76+
77+
There are different ways you can write test for your package Global test which is writing test in Laravel app ( not in Package ) another way is to write tests in package its self , for Global its pretty straight, I will explain how to setup Package test case.
78+
79+
## Create a new composer.json for your package
80+
- On command line navigate to package folder ("contact") and run run `composer init` and follow the directions .
81+
- Add phpunit in your created composer.json file and run `composer install`
82+
83+
```
84+
"require-dev": {
85+
"phpunit/phpunit": "4.8.*"
86+
}
87+
```
88+
89+
## Create a phpunit.xml file in your package dir ("Contact") similar to laravel's phpunit.xml just without bootstrap.
90+
91+
92+
## Create a dir "tests" in your Package ( "Contact" )
93+
94+
- Create common TestPackageCase.php which is very similar to TestCase.php file just with few path changes.
95+
96+
- Create ContactTest.php which extends TestPackageCase.php , now TestPackageCase.php is the common extends files for all tests created in package this allows you create very similarly to laravel's test cases without any major changes.
97+
98+
## Running tests.
99+
100+
On command line Navigate to your package folder ("Contact") and run `../../../vendor/bin/phpunit` this should give you phpunit test case results.
101+
102+
DO share this repository if you liked it.
20103

21-
## Security Vulnerabilities
22104

23-
If you discover a security vulnerability within Laravel, please send an e-mail to Taylor Otwell at [email protected]. All security vulnerabilities will be promptly addressed.
24105

25-
## License
26106

27-
The Laravel framework is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT).

0 commit comments

Comments
 (0)