Making the build self-testing is one of the best pratices of continuous integration. This was the main goal of this presentation, the work done in a REST API, using Symfony, phpspec, PHPUnit and Behat.
Want to learn how to use Selenium from the ground up? This presentation will show you how to start from nothing and build out a well factored, maintainable, resilient, and parallelized set of tests that will run locally, on a Continuous Integration server, and in the cloud. These tests will not only work well, but exercise relevant functionality that matters to the business.
In this presentation, you will be introduced to Clean Code, Code Smells concepts and anti-patterns in programming, what are the common bad patterns of Selenium code and architectural considerations. We will also go though guidelines on how to write maintainable and reusable automation code, automation of complicated websites, PageObject vs ScreenPlay patterns, and common practices in avoiding and debugging of flaky tests.
Introduction to using SpecFlow tool for testing REST API. For beginners that are at least a bit familiar with test automation, and gives some details and hints.
Making the build self-testing is one of the best pratices of continuous integration. This was the main goal of this presentation, the work done in a REST API, using Symfony, phpspec, PHPUnit and Behat.
Want to learn how to use Selenium from the ground up? This presentation will show you how to start from nothing and build out a well factored, maintainable, resilient, and parallelized set of tests that will run locally, on a Continuous Integration server, and in the cloud. These tests will not only work well, but exercise relevant functionality that matters to the business.
In this presentation, you will be introduced to Clean Code, Code Smells concepts and anti-patterns in programming, what are the common bad patterns of Selenium code and architectural considerations. We will also go though guidelines on how to write maintainable and reusable automation code, automation of complicated websites, PageObject vs ScreenPlay patterns, and common practices in avoiding and debugging of flaky tests.
Introduction to using SpecFlow tool for testing REST API. For beginners that are at least a bit familiar with test automation, and gives some details and hints.
How BDD with tools like Cucumber can create a stronger team, a better quality product, and ultimately a more useable API. Given at the #apistrat SF conference 10/24/2013
Automated Acceptance Testing (and tool choice)
Automated acceptance testing has many names: acceptance-test driven development (ATDD), story-test driven development (STDD), agile acceptance testing and, most recently, specification by example. At the heart of all these approaches is to produce business-facing tests which are system tests running end-to-end, picking up regression issues and improving confidence that the code works as required.
In this talk, I will contextualise how each of these approaches share in common a three-tier layering strategy: acceptance criteria, test implementation layer and application driver layer. This is important because applying this approach requires a tool choice and each tool tends to have its own sweet (and blind) spot that is best understood through these layers.
I will first deep dive into sample code across a few tools (Cucumber, Fitnesse, Concordion) to illustrate this layering. I use an example that shows how to decouple the GUI from tests (window driver pattern).
Finally, I will look at some typical client scenarios to examine which tools might best suited because tool choice is not simply a host operating system question (.Net, Java, Ruby).
Functional tests are usually the slowest layer of automated tests for almost every product. They use product via UI, store data in real DB, integrate with external services and do other “slow” things. The first easy answer how to make them fast is to run in parallel. But in reality tests depends on the same data and intersect by some common functionality. In this talk we will review useful techniques and approaches how to win this battle.
BDD (Behavior-driven development), also known as ATDD (Acceptance test–driven development) is a software development process that helps Agile teams design, develop, test and deliver software efficiently, it's about how to implement agile acceptance testing and binding business requirements to code. BDD helps to bridge the communication gap between stakeholders and implementation teams, build quality into software from the start, design, develop and deliver systems fit for purpose. SpecFlow is the official tool to implement BDD on the .NET platform.
Better End-to-End Testing with Page Objects Model using ProtractorKasun Kodagoda
This presentation focuses on implementing Page Objects Model using Protractor for AngularJS apps for more maintainable, reusable and flexible end-to-end testing for your project. The presentations was done at 99X Technology as a Tech Talk session done by Team Finale.
Practical Tips & Tricks for Selenium Test AutomationSauce Labs
Have unanswered Selenium questions? Want to learn how to use Selenium like a Pro? Join Dave Haeffner - author of The Selenium Guidebook - as he steps through the best and most useful tips & tricks from his weekly Selenium tip newsletter (Elemental Selenium).
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...Sargis Sargsyan
One of the painful problems in Selenium automated testing is determining whether a HTML page has been loaded. This is especially the case when web application uses a JS heavy framework such as the popular AngularJS.
How to handle Selenium Page Object pattern better with Loadable Component.
The Loadable Component helps test case developers make sure that the page or a component of the page is loaded successfully. I will share my experience about the concept of the Loadable Component and Page Object patterns.
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Applitools
Written and presented by Fernando Martin.
Automated End-to End-Testing is a two-edged sword; it can be the hero, saving you time during regression testing and preventing faulty releases, or it can be the villain, slowing down the development and release process with flaky, hard to maintain and time-consuming suites that you don't trust or want.
Test automation expert and leading software developer Fernando Martin have seen both. In this talk, he will go through key lessons he learnt, and how he applied them to open source AugmentedDriver - a tool that allowed his team to run more than 80,000 tests in a month, running suites of more than 275 tests in less than 15 minutes.
Watch this in-depth webinar, and learn how to:
Lesson 1: Achieve Throughput: UI tests are inherently slow. Learn how to focus on Parallelism to achieve throughput.
Lesson 2: Achieve Reliability: Learn how to avoid common flakiness pitfalls that make tests unreliable.
Lesson 3: Achieve Modularity and Re-usability: Learn how to architect your framework so it can be easily extended and it can quickly adapt to changes.
Lesson 4: Achieve Encapsulation of Business Logic: Learn how to effectively combine all the previous lessons to make your tests sturdy and readable.
Lesson 5: Achieve Visibility and Transparency: Reporting; consolidating each piece of your framework into something that can be easily understood and digested by the rest of your team.
Lesson 6: Integration and Easy Configuration: Provide easy configuration so the suites can be run effortless by the rest of your team and can be plugged into your CI Systems.
Sauce Labs hosted a Selenium bootcamp webinar with guest speaker Dave Haeffner. This presentation will give you a basis for the detail given in Dave's like titled E-book and get you started with Selenium.
Introduction to cypress in Angular (Chinese)Hong Tat Yew
Cypress framework is a JavaScript-based end-to-end testing framework built on top of Mocha – a feature-rich JavaScript test framework running on and in the browser, making asynchronous testing simple and convenient. Cypress is like Protractor for Angular. In this talk, we will talk about how to write cypress test from scratch and some best practice.
Beyond the Release: CI That Transforms OrganizationsSauce Labs
When DevOps talk meets DevOps tactics, companies are finding that Continuous Integration (CI) is the make or break point. And implementing CI is one thing, but making it healthy and sustainable takes a little bit more consideration.
In this webinar, Chris Riley (DevOps Analyst) and Andy Pemberton (CloudBees) will show you how Jenkins and Sauce Labs can work together to build a comprehensive CI tool set to help you release faster, at a higher quality and with more visibility.
Session from GIDS 2014, showing how to do automated Web testing using a variety of JavaScript frameworks, including QUnit, Jasmine, Protractor, Selenium, and PhantomJS
Web automation with Selenium for software engineersMikalai Alimenkou
We all know Selenium/WebDriver more as testing automation tool. But in reality this is just a tool/library to automate operations with different browsers using similar API from different languages. In this talk I will show how to use different parts of Selenium product family for day to day tasks of developer, QA engineer or even Project Manager. Hope after visiting this talk you will spend less time on boring procedures and improve many things in your current development process.
How BDD with tools like Cucumber can create a stronger team, a better quality product, and ultimately a more useable API. Given at the #apistrat SF conference 10/24/2013
Automated Acceptance Testing (and tool choice)
Automated acceptance testing has many names: acceptance-test driven development (ATDD), story-test driven development (STDD), agile acceptance testing and, most recently, specification by example. At the heart of all these approaches is to produce business-facing tests which are system tests running end-to-end, picking up regression issues and improving confidence that the code works as required.
In this talk, I will contextualise how each of these approaches share in common a three-tier layering strategy: acceptance criteria, test implementation layer and application driver layer. This is important because applying this approach requires a tool choice and each tool tends to have its own sweet (and blind) spot that is best understood through these layers.
I will first deep dive into sample code across a few tools (Cucumber, Fitnesse, Concordion) to illustrate this layering. I use an example that shows how to decouple the GUI from tests (window driver pattern).
Finally, I will look at some typical client scenarios to examine which tools might best suited because tool choice is not simply a host operating system question (.Net, Java, Ruby).
Functional tests are usually the slowest layer of automated tests for almost every product. They use product via UI, store data in real DB, integrate with external services and do other “slow” things. The first easy answer how to make them fast is to run in parallel. But in reality tests depends on the same data and intersect by some common functionality. In this talk we will review useful techniques and approaches how to win this battle.
BDD (Behavior-driven development), also known as ATDD (Acceptance test–driven development) is a software development process that helps Agile teams design, develop, test and deliver software efficiently, it's about how to implement agile acceptance testing and binding business requirements to code. BDD helps to bridge the communication gap between stakeholders and implementation teams, build quality into software from the start, design, develop and deliver systems fit for purpose. SpecFlow is the official tool to implement BDD on the .NET platform.
Better End-to-End Testing with Page Objects Model using ProtractorKasun Kodagoda
This presentation focuses on implementing Page Objects Model using Protractor for AngularJS apps for more maintainable, reusable and flexible end-to-end testing for your project. The presentations was done at 99X Technology as a Tech Talk session done by Team Finale.
Practical Tips & Tricks for Selenium Test AutomationSauce Labs
Have unanswered Selenium questions? Want to learn how to use Selenium like a Pro? Join Dave Haeffner - author of The Selenium Guidebook - as he steps through the best and most useful tips & tricks from his weekly Selenium tip newsletter (Elemental Selenium).
Better Page Object Handling with Loadable Component Pattern - SQA Days 20, Be...Sargis Sargsyan
One of the painful problems in Selenium automated testing is determining whether a HTML page has been loaded. This is especially the case when web application uses a JS heavy framework such as the popular AngularJS.
How to handle Selenium Page Object pattern better with Loadable Component.
The Loadable Component helps test case developers make sure that the page or a component of the page is loaded successfully. I will share my experience about the concept of the Loadable Component and Page Object patterns.
Mastering UI automation at Scale: Key Lessons and Best Practices (By Fernando...Applitools
Written and presented by Fernando Martin.
Automated End-to End-Testing is a two-edged sword; it can be the hero, saving you time during regression testing and preventing faulty releases, or it can be the villain, slowing down the development and release process with flaky, hard to maintain and time-consuming suites that you don't trust or want.
Test automation expert and leading software developer Fernando Martin have seen both. In this talk, he will go through key lessons he learnt, and how he applied them to open source AugmentedDriver - a tool that allowed his team to run more than 80,000 tests in a month, running suites of more than 275 tests in less than 15 minutes.
Watch this in-depth webinar, and learn how to:
Lesson 1: Achieve Throughput: UI tests are inherently slow. Learn how to focus on Parallelism to achieve throughput.
Lesson 2: Achieve Reliability: Learn how to avoid common flakiness pitfalls that make tests unreliable.
Lesson 3: Achieve Modularity and Re-usability: Learn how to architect your framework so it can be easily extended and it can quickly adapt to changes.
Lesson 4: Achieve Encapsulation of Business Logic: Learn how to effectively combine all the previous lessons to make your tests sturdy and readable.
Lesson 5: Achieve Visibility and Transparency: Reporting; consolidating each piece of your framework into something that can be easily understood and digested by the rest of your team.
Lesson 6: Integration and Easy Configuration: Provide easy configuration so the suites can be run effortless by the rest of your team and can be plugged into your CI Systems.
Sauce Labs hosted a Selenium bootcamp webinar with guest speaker Dave Haeffner. This presentation will give you a basis for the detail given in Dave's like titled E-book and get you started with Selenium.
Introduction to cypress in Angular (Chinese)Hong Tat Yew
Cypress framework is a JavaScript-based end-to-end testing framework built on top of Mocha – a feature-rich JavaScript test framework running on and in the browser, making asynchronous testing simple and convenient. Cypress is like Protractor for Angular. In this talk, we will talk about how to write cypress test from scratch and some best practice.
Beyond the Release: CI That Transforms OrganizationsSauce Labs
When DevOps talk meets DevOps tactics, companies are finding that Continuous Integration (CI) is the make or break point. And implementing CI is one thing, but making it healthy and sustainable takes a little bit more consideration.
In this webinar, Chris Riley (DevOps Analyst) and Andy Pemberton (CloudBees) will show you how Jenkins and Sauce Labs can work together to build a comprehensive CI tool set to help you release faster, at a higher quality and with more visibility.
Session from GIDS 2014, showing how to do automated Web testing using a variety of JavaScript frameworks, including QUnit, Jasmine, Protractor, Selenium, and PhantomJS
Web automation with Selenium for software engineersMikalai Alimenkou
We all know Selenium/WebDriver more as testing automation tool. But in reality this is just a tool/library to automate operations with different browsers using similar API from different languages. In this talk I will show how to use different parts of Selenium product family for day to day tasks of developer, QA engineer or even Project Manager. Hope after visiting this talk you will spend less time on boring procedures and improve many things in your current development process.
Object Oriented Design Principles
~ How to become a SOLID programmer ~
~ A guide to make a well-designed application with Laravel ~
"Proper Object Oriented Design makes a developer's life easy, whereas bad design makes it a disaster"
We investigate one of the most popular approaches to creating software: test driven development. From the basic understanding why tests are important to a new software development paradigm, where you start with tests and them do the implementation. We glance over different areas of testing and see how one should really do the software testing in different situation.
Improving the Quality of Existing SoftwareSteven Smith
Given at DogFoodCon 2016 in Columbus, Ohio
As developers, most of our time is spent working on existing software – even if it’s just the software we wrote ourselves, yesterday. And over time, software rots. If were not diligent, our beautiful code can degrade into a worthless mess. Keeping our code in working condition is no different than changing the oil in our car “ its preventive maintenance. In this session, Steve will cover some common places to look for signs of degradation in existing applications, and describe the steps we can take to improve our code. Examples will use C# and primarily ASP.NET.
Improving the Quality of Existing SoftwareSteven Smith
How do you improve the quality of your existing software, while continuing to add value for your customers? What are some heuristics and code smells you can look for, and principles and patterns you can use to guide you, as you make your software better over time instead of worse?
Getting Started with Test-Driven Development at PHPtek 2023Scott Keck-Warren
In this presentation I explain how to get started with TDD in PHP including using a testing framework, including it in your CI/CD process, and common gotchas.
Start with passing tests (tdd for bugs) v0.5 (22 sep 2016)Dinis Cruz
"Turning TDD upside down - For bugs, always start with a passing test" - Common workflow on TDD is to write failed tests. The problem with this approach is that it only works for a very specific scenario (when fixing bugs). This presentation will present a different workflow which will make the coding and testing of those tests much easier, faster, simpler, secure and thorough'
Presented at LSCC (London Software Craftsmanship Community) http://www.meetup.com/london-software-craftsmanship on sep 2016.
Improving the Quality of Existing Software - DevIntersection April 2016Steven Smith
How do you improve the quality of your existing software, while continuing to add value for your customers? What are some heuristics and code smells you can look for, and principles and patterns you can use to guide you, as you make your software better over time instead of worse? How can we improve our skills and techniques so that writing high quality software becomes our default, fastest way of working?
Comprehensive Validation with Laravel 4Kirk Bushell
Taking basic validation rules to a more manageable, readable state by implementing architectural solutions that make our validation requirements beautiful.
Bridging the communication Gap & Continuous Deliverymasoodjan
This is a case study of a top retailer in UK which was following Agile but not all the Agile practices. We will discuss how collaboration between business and engineering team improved using BDD and how it was used to generate automated acceptance tests. We will also discuss how continuous integration was implemented which laid foundation for continuous delivery.
DefCore: The Interoperability Standard for OpenStackMark Voelker
This presentation provides an introduction to the OpenStack DefCore Committee, which is working to create interoperability standards for OpenStack Powered clouds. You'll gain insight into the interoperability challenges of OpenStack clouds, and learn how DefCore creates it's Guidelines. Learn why the Technical Committee, Board of Directors, end users, and vendors have a seat at the table. You'll laugh, you'll cry, you'll immediately want to stop talking about cloud computing and go watch science fiction all night.
This talk was originally presented at the Triangle OpenStack Meetup Group's September 21, 2015 meeting in Durham, NC. A recording can be found here (this talk starts at the 46:10 mark): https://vmware.webex.com/vmware/lsr.php?RCID=a51f9e6882f54ccab8b715c8c0162484
A new revision with updates was given at a meeting of the China Open Source Cloud League on May 20, 2016 in Beijing. The slides here on Slideshare represent that presentation.
First Section:
Continuous Delivery as a software engineering approach.
(This is beneficial for Project Managers, DEVs & QAs.)
1. Projects Case Studies to explain why you should adopt Continuous Delivery.
2. Advantages & Reasons for releasing software more frequently.
3. How to make a Reliable / Production Ready Software.
4. Ingredients of Continues Delivery.
5. Tools/ approaches to choose while using Continues Delivery Methodology.
Second Section:
Technical side of Continuous Delivery.
(This is more beneficial for DEVs/ QAs than Project Managers.)
1. Testing a Software.
2. Measuring Code Quality / Analytic to visualize teams performances.
3. Tools: Code Syntax Checker, Testing Framework, Build Automation, Automated Reporting/ Analytic Dashboard.
4. Continuous Delivery Automation over Cloud using Travis CI - Live demonstration.
Third Section:
1. Sample Projects for audience to adopt right tools for development, testing & deployments.
2. Q&A.
-------------------------------------------------
By Waqar Alamgir http://waqaralamgir.tk
This talk provides an introduction to the OpenStack Interop Working Group, what it does, and how it works. We'll also look into some upcoming new work, such as the development of vertical programs (e.g. for clouds being built for NFV or other specific use cases).
Five Enterprise Development Best Practices That EVERY Salesforce Org Can UseSalesforce Developers
In any environment, non-existent or ad-hoc standards greatly contribute to technical debt. Join us as we explain why Salesforce's multi-tenant architecture and its platform and governor limits make managing technical debt in the App Cloud so critical. You'll discover five best-practices that can make an immediate impact on the maintainability and scalability of your org.
Helpful Automation Techniques - Selenium Camp 2014Justin Ison
Utilize REST to shorten test time and reduce flakiness.
Proxy your way to shorter test runs without full integration tests.
Framework you’re using has a bug? Use the Selenium API as a work around!
Using recycled concrete aggregates (RCA) for pavements is crucial to achieving sustainability. Implementing RCA for new pavement can minimize carbon footprint, conserve natural resources, reduce harmful emissions, and lower life cycle costs. Compared to natural aggregate (NA), RCA pavement has fewer comprehensive studies and sustainability assessments.
We have compiled the most important slides from each speaker's presentation. This year’s compilation, available for free, captures the key insights and contributions shared during the DfMAy 2024 conference.
Forklift Classes Overview by Intella PartsIntella Parts
Discover the different forklift classes and their specific applications. Learn how to choose the right forklift for your needs to ensure safety, efficiency, and compliance in your operations.
For more technical information, visit our website https://intellaparts.com
Industrial Training at Shahjalal Fertilizer Company Limited (SFCL)MdTanvirMahtab2
This presentation is about the working procedure of Shahjalal Fertilizer Company Limited (SFCL). A Govt. owned Company of Bangladesh Chemical Industries Corporation under Ministry of Industries.
Cosmetic shop management system project report.pdfKamal Acharya
Buying new cosmetic products is difficult. It can even be scary for those who have sensitive skin and are prone to skin trouble. The information needed to alleviate this problem is on the back of each product, but it's thought to interpret those ingredient lists unless you have a background in chemistry.
Instead of buying and hoping for the best, we can use data science to help us predict which products may be good fits for us. It includes various function programs to do the above mentioned tasks.
Data file handling has been effectively used in the program.
The automated cosmetic shop management system should deal with the automation of general workflow and administration process of the shop. The main processes of the system focus on customer's request where the system is able to search the most appropriate products and deliver it to the customers. It should help the employees to quickly identify the list of cosmetic product that have reached the minimum quantity and also keep a track of expired date for each cosmetic product. It should help the employees to find the rack number in which the product is placed.It is also Faster and more efficient way.
Student information management system project report ii.pdfKamal Acharya
Our project explains about the student management. This project mainly explains the various actions related to student details. This project shows some ease in adding, editing and deleting the student details. It also provides a less time consuming process for viewing, adding, editing and deleting the marks of the students.
NUMERICAL SIMULATIONS OF HEAT AND MASS TRANSFER IN CONDENSING HEAT EXCHANGERS...ssuser7dcef0
Power plants release a large amount of water vapor into the
atmosphere through the stack. The flue gas can be a potential
source for obtaining much needed cooling water for a power
plant. If a power plant could recover and reuse a portion of this
moisture, it could reduce its total cooling water intake
requirement. One of the most practical way to recover water
from flue gas is to use a condensing heat exchanger. The power
plant could also recover latent heat due to condensation as well
as sensible heat due to lowering the flue gas exit temperature.
Additionally, harmful acids released from the stack can be
reduced in a condensing heat exchanger by acid condensation. reduced in a condensing heat exchanger by acid condensation.
Condensation of vapors in flue gas is a complicated
phenomenon since heat and mass transfer of water vapor and
various acids simultaneously occur in the presence of noncondensable
gases such as nitrogen and oxygen. Design of a
condenser depends on the knowledge and understanding of the
heat and mass transfer processes. A computer program for
numerical simulations of water (H2O) and sulfuric acid (H2SO4)
condensation in a flue gas condensing heat exchanger was
developed using MATLAB. Governing equations based on
mass and energy balances for the system were derived to
predict variables such as flue gas exit temperature, cooling
water outlet temperature, mole fraction and condensation rates
of water and sulfuric acid vapors. The equations were solved
using an iterative solution technique with calculations of heat
and mass transfer coefficients and physical properties.
Hierarchical Digital Twin of a Naval Power SystemKerry Sado
A hierarchical digital twin of a Naval DC power system has been developed and experimentally verified. Similar to other state-of-the-art digital twins, this technology creates a digital replica of the physical system executed in real-time or faster, which can modify hardware controls. However, its advantage stems from distributing computational efforts by utilizing a hierarchical structure composed of lower-level digital twin blocks and a higher-level system digital twin. Each digital twin block is associated with a physical subsystem of the hardware and communicates with a singular system digital twin, which creates a system-level response. By extracting information from each level of the hierarchy, power system controls of the hardware were reconfigured autonomously. This hierarchical digital twin development offers several advantages over other digital twins, particularly in the field of naval power systems. The hierarchical structure allows for greater computational efficiency and scalability while the ability to autonomously reconfigure hardware controls offers increased flexibility and responsiveness. The hierarchical decomposition and models utilized were well aligned with the physical twin, as indicated by the maximum deviations between the developed digital twin hierarchy and the hardware.
2. Who the hell am I?
• Technical Lead for Tectonic Digital (www.tectonic.com.au)
• Software architect for http://awardforce.com
• Technical writer (see: http://kirkbushell.me)
• Open source contributor (Laravel 3/4, various other projects)
• http://github.com/kirkbushell
• Also known as Oddman on IRC, forums.etc.
• @kirkbushell
6. In addition...
• I'll assume you know a couple of things about validation and
• You know or at least understand some of the concepts of Laravel
4, including:
• Dependency injection and
• The IoC feature
• I start work at 4.30am (apologies if I'm not quite with it)
7. Why?
• There's been a lot of talk in the community the last 6 months
about validation
• How we can do it well - lots of different opinions
• I have a pretty strong opinion on this matter
8. What we're going to cover
• A brief history of MVC, the repository pattern and why validation
should be its own domain
• Implementing validation within an API context
• Using exceptions for greater readability
• Catching exceptions to generate API responses automagically
• The end result - cleaner code
9. What I'm not going to talk about
• RESTful APIs
• The view layer
10. A brief history of everything MVC.
• A blessing to web development (and software development in
general)
• Fat controllers, skinny models
• Skinny controllers, fat models
• Validation tied up in models (along with everything else)
• We still seem to be stuck on the previous point.
11. Introducing.. the repository pattern?
• Helped clean up models
• Query building and object management
• So, what about validation?
12. Validate all the things!
• Validation within models breaks the single responsibility principle
• Validation in models doesn't make much sense if you're using the
repository pattern
• Implemented via the controller or a service (such as a user
registration service)
14. The validate method
Please read Jason Lewis' article: http://jasonlewis.me/article/laravel-
advanced-validation
// Validate function from article
protected function validate()
{
$this->validator = Validator::make($this->input, $this->rules);
if ($this->validator->fails())
{
throw new ValidateException($this->validator);
}
}
15. ValidateException
class ValidateException extends Exception
{
protected $validator;
public function __construct(Validator $validator)
{
$this->message = 'Validation has failed, or something.';
$this->validator = $validator;
}
public function getErrors()
{
return $this->validator->messages();
}
}
16. Our code, our rules
Implement our own custom rules for user registration:
// UserValidator class
class UserValidator extends Validator
{
public function register()
{
$this->rules = [
'email' => ['required', 'email'],
'password' => ['required']
];
$this->validate();
}
}
17. Validate!
Within our controller, load up our validator and validate the input.
// UserController
public function postRegister()
{
$input = Input::get();
App::make('UserValidator', [$input])->register();
return User::create($input);
}
18. Now what?
• When validation fails it will throw an exception:
if ($this->validator->fails())
{
throw new ValidateException($this->validator);
}
• We need to catch that exception and return a nice status code and
error message, along with any validation errors.
• Laravel 4 provides an excellent way of managing this.
19. Laravel 4 error handling
Create an error handler that is specific to validation exceptions:
App::error(function(ValidateException $exception)
{
$errorResponse = [
'message' => $exception->getMessage(),
'errors' => $exception->getErrors()
];
return Response::json($errorResponse, 422); // Unprocessable entity
});
20. In conclusion
• Complex validation should be in its own domain
• Helps to clean up our code, making it more readable
• Let the framework handle exceptions for you!
• Best for large applications (not so applicable to small apps)