Skip to content

Commit

Permalink
Improve PackagistPhpVersionService testing
Browse files Browse the repository at this point in the history
* resurrected some of the relevant older tests.
* remove the api json array expand logics from test.
  • Loading branch information
yookoala committed Feb 17, 2022
1 parent 5c134eb commit d0127c4
Showing 1 changed file with 74 additions and 75 deletions.
149 changes: 74 additions & 75 deletions services/packagist/packagist-php-version.spec.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,47 @@
import { expect } from 'chai'
import { NotFound } from '../index.js'
import { BasePackagistService } from './packagist-base.js'
import PackagistPhpVersion from './packagist-php-version.service.js'

describe('PackagistPhpVersion', function () {
const json = {
packages: {
'frodo/the-one-package': [
const versions = [
{
version: 'dev-main',
require: { php: '^7.4 || 8' },
},
{
version: 'dev-2.x',
require: { php: '^7.2' },
},
{
version: 'dev-1.x',
require: { php: '^5.6 || ^7' },
},
{
version: '3.0.0',
require: { php: '^7.4 || 8' },
},
{
version: '2.0.0',
require: { php: '^7.2' },
},
{
version: '1.0.0',
require: { php: '^5.6 || ^7' },
},
]

it('should throw NotFound when package version is missing', function () {
expect(() => PackagistPhpVersion.prototype.getPhpVersion(versions, '4.0.0'))
.to.throw(NotFound)
.with.property('prettyMessage', 'invalid version')
})

it('should throw NotFound when PHP version not found on package when using default release', async function () {
expect(() =>
PackagistPhpVersion.prototype.getPhpVersion([
{
version: '3.0.0',
require: { php: '^7.4 || 8' },
require: { php: '^7.2' },
},
{
version: '2.0.0',
Expand All @@ -19,57 +51,16 @@ describe('PackagistPhpVersion', function () {
version: '1.0.0',
require: { php: '^5.6 || ^7' },
},
],
},
}
it('should throw NotFound when package version is missing', function () {
expect(() =>
PackagistPhpVersion.prototype.getPhpVersion(
BasePackagistService.expandPackageVersions(
json,
'frodo/the-one-package'
),
'4.0.0'
)
)
.to.throw(NotFound)
.with.property('prettyMessage', 'invalid version')
})

it('should throw NotFound when PHP version not found on package when using default release', async function () {
const specJson = {
packages: {
'frodo/the-one-package': [
{
version: '3.0.0',
},
{
version: '2.0.0',
require: { php: '^7.2' },
},
{
version: '1.0.0',
require: { php: '^5.6 || ^7' },
},
],
},
}
expect(() =>
PackagistPhpVersion.prototype.getPhpVersion(
BasePackagistService.expandPackageVersions(
specJson,
'frodo/the-one-package'
)
)
])
)
.to.throw(NotFound)
.with.property('prettyMessage', 'version requirement not found')
})

it('should throw NotFound when PHP version not found on package when using specified release', async function () {
const specJson = {
packages: {
'frodo/the-one-package': [
expect(() =>
PackagistPhpVersion.prototype.getPhpVersion(
[
{
version: '3.0.0',
require: { php: '^7.4 || 8' },
Expand All @@ -80,17 +71,8 @@ describe('PackagistPhpVersion', function () {
},
{
version: '1.0.0',
require: '__unset',
},
],
},
}
expect(() =>
PackagistPhpVersion.prototype.getPhpVersion(
BasePackagistService.expandPackageVersions(
specJson,
'frodo/the-one-package'
),
'1.0.0'
)
)
Expand All @@ -99,29 +81,46 @@ describe('PackagistPhpVersion', function () {
})

it('should return PHP version for the default release', async function () {
expect(
PackagistPhpVersion.prototype.getPhpVersion(
BasePackagistService.expandPackageVersions(
json,
'frodo/the-one-package'
)
)
)
expect(() => PackagistPhpVersion.prototype.getPhpVersion(versions))
.to.have.property('phpVersion')
.that.equals('^7.4 || 8')
})

it('should return PHP version for the specified release', async function () {
expect(() => PackagistPhpVersion.prototype.getPhpVersion(versions), '2.0.0')
.to.have.property('phpVersion')
.that.equals('^7.2')
})

it('should throw NotFound when package version is missing', function () {
expect(() =>
PackagistPhpVersion.prototype.getPhpVersion([{ version: '1.0.x-dev' }])
)
.to.throw(NotFound)
.with.property('prettyMessage', 'version requirement not found')

expect(() =>
PackagistPhpVersion.prototype.getPhpVersion([
{ version: '1.0.x-dev', require: {} },
])
)
.to.throw(NotFound)
.with.property('prettyMessage', 'version requirement not found')
})

it('should return PHP version for the default branch', function () {
expect(
PackagistPhpVersion.prototype.getPhpVersion(
BasePackagistService.expandPackageVersions(
json,
'frodo/the-one-package'
),
'2.0.0'
)
PackagistPhpVersion.prototype.getPhpVersion([
{ version: 'dev-1.x', require: { php: '^7.3' } },
{
version: 'dev-2.x',
require: { php: '^7.4 || 8' },
'default-branch': true,
},
{ version: 'dev-3.x', require: { php: '^8.1' } },
])
)
.to.have.property('phpVersion')
.that.equals('^7.2')
.that.equals('^7.4 || 8')
})
})

0 comments on commit d0127c4

Please sign in to comment.