Skip to content

Commit 4041485

Browse files
taufeksds
authored andcommittedFeb 10, 2018
Add PhpUnit Hook for PrePush
Add `PhpUnit` test runner hook for `PrePush` context.
1 parent b178184 commit 4041485

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed
 

‎config/default.yml

+7
Original file line numberDiff line numberDiff line change
@@ -1129,6 +1129,13 @@ PrePush:
11291129
command: ['ruby', '-Ilib:test', '-rminitest', "-e 'exit! Minitest.run'"]
11301130
include: 'test/**/*_test.rb'
11311131

1132+
PhpUnit:
1133+
enabled: false
1134+
description: 'Run PhpUnit test suite'
1135+
command: 'vendor/bin/phpunit'
1136+
flags: ['--bootstrap', 'vendor/autoload.php', 'tests']
1137+
install_command: 'composer require --dev phpunit/phpunit'
1138+
11321139
ProtectedBranches:
11331140
enabled: false
11341141
description: 'Check for illegal pushes to protected branches'
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
module Overcommit::Hook::PrePush
2+
# Runs `phpunit` test suite before push
3+
#
4+
# @see https://phpunit.de/
5+
class PhpUnit < Base
6+
def run
7+
result = execute(command)
8+
return :pass if result.success?
9+
10+
output = result.stdout + result.stderr
11+
[:fail, output]
12+
end
13+
end
14+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
require 'spec_helper'
2+
3+
describe Overcommit::Hook::PrePush::PhpUnit do
4+
let(:config) { Overcommit::ConfigurationLoader.default_configuration }
5+
let(:context) { double('context') }
6+
subject { described_class.new(config, context) }
7+
8+
context 'when phpunit exits successfully' do
9+
before do
10+
result = double('result')
11+
result.stub(:success?).and_return(true)
12+
subject.stub(:execute).and_return(result)
13+
end
14+
15+
it { should pass }
16+
end
17+
18+
context 'when phpunit exits unsucessfully' do
19+
before do
20+
result = double('result')
21+
result.stub(:success?).and_return(false)
22+
result.stub(:stdout).and_return('Some error message')
23+
result.stub(:stderr).and_return('')
24+
subject.stub(:execute).and_return(result)
25+
end
26+
27+
it { should fail_hook 'Some error message' }
28+
end
29+
end

0 commit comments

Comments
 (0)