language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
chartjs
Chart.js
f5b4a0fa3c933ac443b66cfa3e0198f4f342a410.json
Improve test coverage and fix minor issues found (#7713) * Registry * Element * Animation * Animations * Animator
test/specs/core.element.tests.js
@@ -0,0 +1,16 @@ +describe('Chart.element', function() { + describe('getProps', function() { + it('should return requested properties', function() { + const elem = new Chart.Element(); + elem.x = 10; + elem.y = 1.5; + + expect(elem.getProps(['x', 'y'])).toEqual(jasmine.objectContaining({x: 10, y: 1.5})); + expect(elem.getProps(['x', 'y'], true)).toEqual(jasmine.objectContaining({x: 10, y: 1.5})); + + elem.$animations = {x: {active: true, _to: 20}}; + expect(elem.getProps(['x', 'y'])).toEqual(jasmine.objectContaining({x: 10, y: 1.5})); + expect(elem.getProps(['x', 'y'], true)).toEqual(jasmine.objectContaining({x: 20, y: 1.5})); + }); + }); +});
true
Other
chartjs
Chart.js
f5b4a0fa3c933ac443b66cfa3e0198f4f342a410.json
Improve test coverage and fix minor issues found (#7713) * Registry * Element * Animation * Animations * Animator
test/specs/core.registry.tests.js
@@ -64,7 +64,7 @@ describe('Chart.registry', function() { expect(Chart.defaults.elements.myElement).not.toBeDefined(); }); - it('should handle a classig plugin', function() { + it('should handle a classic plugin', function() { const CustomPlugin = { id: 'customPlugin', defaults: { @@ -172,4 +172,169 @@ describe('Chart.registry', function() { Chart.register(FaultyPlugin); }).toThrow(new Error('class does not have id: class FaultyPlugin {}')); }); + + it('should not fail when unregistering an object that is not registered', function() { + expect(function() { + Chart.unregister({id: 'foo'}); + }).not.toThrow(); + }); + + describe('Should allow registering explicitly', function() { + class customExtension {} + customExtension.id = 'custom'; + customExtension.defaults = { + prop: true + }; + + it('as controller', function() { + Chart.registry.addControllers(customExtension); + + expect(Chart.registry.getController('custom')).toEqual(customExtension); + expect(Chart.defaults.custom).toEqual(customExtension.defaults); + + Chart.registry.removeControllers(customExtension); + + expect(function() { + Chart.registry.getController('custom'); + }).toThrow(new Error('"custom" is not a registered controller.')); + expect(Chart.defaults.custom).not.toBeDefined(); + }); + + it('as scale', function() { + Chart.registry.addScales(customExtension); + + expect(Chart.registry.getScale('custom')).toEqual(customExtension); + expect(Chart.defaults.scales.custom).toEqual(customExtension.defaults); + + Chart.registry.removeScales(customExtension); + + expect(function() { + Chart.registry.getScale('custom'); + }).toThrow(new Error('"custom" is not a registered scale.')); + expect(Chart.defaults.scales.custom).not.toBeDefined(); + }); + + it('as element', function() { + Chart.registry.addElements(customExtension); + + expect(Chart.registry.getElement('custom')).toEqual(customExtension); + expect(Chart.defaults.elements.custom).toEqual(customExtension.defaults); + + Chart.registry.removeElements(customExtension); + + expect(function() { + Chart.registry.getElement('custom'); + }).toThrow(new Error('"custom" is not a registered element.')); + expect(Chart.defaults.elements.custom).not.toBeDefined(); + }); + + it('as plugin', function() { + Chart.registry.addPlugins(customExtension); + + expect(Chart.registry.getPlugin('custom')).toEqual(customExtension); + expect(Chart.defaults.plugins.custom).toEqual(customExtension.defaults); + + Chart.registry.removePlugins(customExtension); + + expect(function() { + Chart.registry.getPlugin('custom'); + }).toThrow(new Error('"custom" is not a registered plugin.')); + expect(Chart.defaults.plugins.custom).not.toBeDefined(); + }); + }); + + it('should fire before/after callbacks', function() { + let beforeRegisterCount = 0; + let afterRegisterCount = 0; + let beforeUnregisterCount = 0; + let afterUnregisterCount = 0; + class custom {} + custom.id = 'custom'; + custom.beforeRegister = () => beforeRegisterCount++; + custom.afterRegister = () => afterRegisterCount++; + custom.beforeUnregister = () => beforeUnregisterCount++; + custom.afterUnregister = () => afterUnregisterCount++; + + Chart.registry.addControllers(custom); + expect(beforeRegisterCount).withContext('beforeRegister').toBe(1); + expect(afterRegisterCount).withContext('afterRegister').toBe(1); + Chart.registry.removeControllers(custom); + expect(beforeUnregisterCount).withContext('beforeUnregister').toBe(1); + expect(afterUnregisterCount).withContext('afterUnregister').toBe(1); + + Chart.registry.addScales(custom); + expect(beforeRegisterCount).withContext('beforeRegister').toBe(2); + expect(afterRegisterCount).withContext('afterRegister').toBe(2); + Chart.registry.removeScales(custom); + expect(beforeUnregisterCount).withContext('beforeUnregister').toBe(2); + expect(afterUnregisterCount).withContext('afterUnregister').toBe(2); + + Chart.registry.addElements(custom); + expect(beforeRegisterCount).withContext('beforeRegister').toBe(3); + expect(afterRegisterCount).withContext('afterRegister').toBe(3); + Chart.registry.removeElements(custom); + expect(beforeUnregisterCount).withContext('beforeUnregister').toBe(3); + expect(afterUnregisterCount).withContext('afterUnregister').toBe(3); + + Chart.register(custom); + expect(beforeRegisterCount).withContext('beforeRegister').toBe(4); + expect(afterRegisterCount).withContext('afterRegister').toBe(4); + Chart.unregister(custom); + expect(beforeUnregisterCount).withContext('beforeUnregister').toBe(4); + expect(afterUnregisterCount).withContext('afterUnregister').toBe(4); + }); + + it('should not register anything that would collide with existing defaults', function() { + class testController extends Chart.DatasetController {} + testController.id = 'events'; + expect(function() { + Chart.register(testController); + }).toThrow(new Error('Can not register "events", because "defaults.events" would collide with existing defaults')); + }); + + describe('should handle multiple items', function() { + class test1 extends Chart.DatasetController {} + test1.id = 'test1'; + class test2 extends Chart.Scale {} + test2.id = 'test2'; + + it('separately', function() { + Chart.register(test1, test2); + expect(Chart.registry.getController('test1')).toEqual(test1); + expect(Chart.registry.getScale('test2')).toEqual(test2); + Chart.unregister(test1, test2); + expect(function() { + Chart.registry.getController('test1'); + }).toThrow(); + expect(function() { + Chart.registry.getScale('test2'); + }).toThrow(); + }); + + it('as array', function() { + Chart.register([test1, test2]); + expect(Chart.registry.getController('test1')).toEqual(test1); + expect(Chart.registry.getScale('test2')).toEqual(test2); + Chart.unregister([test1, test2]); + expect(function() { + Chart.registry.getController('test1'); + }).toThrow(); + expect(function() { + Chart.registry.getScale('test2'); + }).toThrow(); + }); + + it('as object', function() { + Chart.register({test1, test2}); + expect(Chart.registry.getController('test1')).toEqual(test1); + expect(Chart.registry.getScale('test2')).toEqual(test2); + Chart.unregister({test1, test2}); + expect(function() { + Chart.registry.getController('test1'); + }).toThrow(); + expect(function() { + Chart.registry.getScale('test2'); + }).toThrow(); + }); + }); });
true
Other
chartjs
Chart.js
f79d609548aebc6d70b16a51a80574827f051713.json
Add offset option for arc (#7691) * Add offset option for arc * Finishing touches
docs/docs/charts/doughnut.mdx
@@ -10,9 +10,22 @@ Pie and doughnut charts are effectively the same class in Chart.js, but have one They are also registered under two aliases in the `Chart` core. Other than their different default value, and different alias, they are exactly the same. -import { useEffect } from 'react'; - -export const ExampleChart = () => { +import { useEffect, useRef } from 'react'; +import Tabs from '@theme/Tabs'; +import TabItem from '@theme/TabItem'; + +<Tabs + defaultValue='doughnut' + values={[ + {label: 'Doughnut', value: 'doughnut' }, + {label: 'Pie', value: 'pie' }, + ]} +> +<TabItem value="doughnut"> + +```jsx live +function example() { + const canvas = useRef(null); useEffect(() => { const cfg = { type: 'doughnut', @@ -29,36 +42,53 @@ export const ExampleChart = () => { 'rgb(255, 99, 132)', 'rgb(54, 162, 235)', 'rgb(255, 205, 86)' - ] + ], + hoverOffset: 4 }] } }; - new Chart(document.getElementById('chartjs-0').getContext('2d'), cfg); + new Chart(canvas.current.getContext('2d'), cfg); }); - return <div className="chartjs-wrapper"><canvas id="chartjs-0" className="chartjs"></canvas></div>; + return <div className="chartjs-wrapper"><canvas ref={canvas} className="chartjs"></canvas></div>; } +``` -<ExampleChart/> +</TabItem> -## Example Usage +<TabItem value="pie"> -```javascript -// For a pie chart -var myPieChart = new Chart(ctx, { - type: 'pie', - data: data, - options: options -}); +```jsx live +function example() { + const canvas = useRef(null); + useEffect(() => { + const cfg = { + type: 'pie', + data: { + labels: [ + 'Red', + 'Blue', + 'Yellow' + ], + datasets: [{ + label: 'My First Dataset', + data: [300, 50, 100], + backgroundColor: [ + 'rgb(255, 99, 132)', + 'rgb(54, 162, 235)', + 'rgb(255, 205, 86)' + ], + hoverOffset: 4 + }] + } + }; + new Chart(canvas.current.getContext('2d'), cfg); + }); + return <div className="chartjs-wrapper"><canvas ref={canvas} className="chartjs"></canvas></div>; +} ``` -```javascript -// And for a doughnut chart -var myDoughnutChart = new Chart(ctx, { - type: 'doughnut', - data: data, - options: options -}); -``` +</TabItem> +</Tabs> ## Dataset Properties @@ -75,6 +105,8 @@ The doughnut/pie chart allows a number of properties to be specified for each da | [`hoverBackgroundColor`](#interations) | [`Color`](../general/colors.md) | Yes | Yes | `undefined` | [`hoverBorderColor`](#interactions) | [`Color`](../general/colors.md) | Yes | Yes | `undefined` | [`hoverBorderWidth`](#interactions) | `number` | Yes | Yes | `undefined` +| [`hoverOffset`](#interactions) | `number` | Yes | Yes | `0` +| [`offset`](#styling) | `number` | Yes | Yes | `0` | [`weight`](#styling) | `number` | - | - | `1` ### General @@ -93,6 +125,7 @@ The style of each arc can be controlled with the following properties: | `backgroundColor` | arc background color. | `borderColor` | arc border color. | `borderWidth` | arc border width (in pixels). +| `offset` | arc offset (in pixels). | `weight` | The relative thickness of the dataset. Providing a value for weight will cause the pie or doughnut dataset to be drawn with a thickness relative to the sum of all the dataset weight values. All these values, if `undefined`, fallback to the associated [`elements.arc.*`](../configuration/elements.md#arc-configuration) options. @@ -114,6 +147,7 @@ The interaction with each arc can be controlled with the following properties: | `hoverBackgroundColor` | arc background color when hovered. | `hoverBorderColor` | arc border color when hovered. | `hoverBorderWidth` | arc border width when hovered (in pixels). +| `hoverOffset` | arc offset when hovered (in pixels). All these values, if `undefined`, fallback to the associated [`elements.arc.*`](../configuration/elements.md#arc-configuration) options.
true
Other
chartjs
Chart.js
f79d609548aebc6d70b16a51a80574827f051713.json
Add offset option for arc (#7691) * Add offset option for arc * Finishing touches
src/controllers/controller.doughnut.js
@@ -89,9 +89,9 @@ export default class DoughnutController extends DatasetController { const cutout = options.cutoutPercentage / 100 || 0; const chartWeight = me._getRingWeight(me.index); const {ratioX, ratioY, offsetX, offsetY} = getRatioAndOffset(options.rotation, options.circumference, cutout); - const borderWidth = me.getMaxBorderWidth(); - const maxWidth = (chartArea.right - chartArea.left - borderWidth) / ratioX; - const maxHeight = (chartArea.bottom - chartArea.top - borderWidth) / ratioY; + const spacing = me.getMaxBorderWidth() + me.getMaxOffset(arcs); + const maxWidth = (chartArea.right - chartArea.left - spacing) / ratioX; + const maxHeight = (chartArea.bottom - chartArea.top - spacing) / ratioY; const outerRadius = Math.max(Math.min(maxWidth, maxHeight) / 2, 0); const innerRadius = Math.max(outerRadius * cutout, 0); const radiusLength = (outerRadius - innerRadius) / me._getVisibleDatasetWeightTotal(); @@ -219,6 +219,16 @@ export default class DoughnutController extends DatasetController { return max; } + getMaxOffset(arcs) { + let max = 0; + + for (let i = 0, ilen = arcs.length; i < ilen; ++i) { + const options = this.resolveDataElementOptions(i); + max = Math.max(max, options.offset || 0, options.hoverOffset || 0); + } + return max; + } + /** * Get radius length offset of the dataset in relation to the visible datasets weights. This allows determining the inner and outer radius correctly * @private @@ -264,14 +274,12 @@ DoughnutController.defaults = { 'borderColor', 'borderWidth', 'borderAlign', - 'hoverBackgroundColor', - 'hoverBorderColor', - 'hoverBorderWidth', + 'offset' ], animation: { numbers: { type: 'number', - properties: ['circumference', 'endAngle', 'innerRadius', 'outerRadius', 'startAngle', 'x', 'y'] + properties: ['circumference', 'endAngle', 'innerRadius', 'outerRadius', 'startAngle', 'x', 'y', 'offset', 'borderWidth'] }, // Boolean - Whether we animate the rotation of the Doughnut animateRotate: true,
true
Other
chartjs
Chart.js
f79d609548aebc6d70b16a51a80574827f051713.json
Add offset option for arc (#7691) * Add offset option for arc * Finishing touches
src/controllers/controller.polarArea.js
@@ -148,9 +148,7 @@ PolarAreaController.defaults = { 'borderColor', 'borderWidth', 'borderAlign', - 'hoverBackgroundColor', - 'hoverBorderColor', - 'hoverBorderWidth' + 'offset' ], animation: {
true
Other
chartjs
Chart.js
f79d609548aebc6d70b16a51a80574827f051713.json
Add offset option for arc (#7691) * Add offset option for arc * Finishing touches
src/core/core.datasetController.js
@@ -714,7 +714,7 @@ export default class DatasetController { /** * @param {number} index - * @param {string} mode + * @param {string} [mode] * @protected */ resolveDataElementOptions(index, mode) {
true
Other
chartjs
Chart.js
f79d609548aebc6d70b16a51a80574827f051713.json
Add offset option for arc (#7691) * Add offset option for arc * Finishing touches
src/elements/element.arc.js
@@ -3,17 +3,17 @@ import {_angleBetween, getAngleFromPoint} from '../helpers/helpers.math'; const TAU = Math.PI * 2; -function clipArc(ctx, model) { - const {startAngle, endAngle, pixelMargin, x, y} = model; - let angleMargin = pixelMargin / model.outerRadius; +function clipArc(ctx, element) { + const {startAngle, endAngle, pixelMargin, x, y, outerRadius, innerRadius} = element; + let angleMargin = pixelMargin / outerRadius; // Draw an inner border by cliping the arc and drawing a double-width border // Enlarge the clipping arc by 0.33 pixels to eliminate glitches between borders ctx.beginPath(); - ctx.arc(x, y, model.outerRadius, startAngle - angleMargin, endAngle + angleMargin); - if (model.innerRadius > pixelMargin) { - angleMargin = pixelMargin / model.innerRadius; - ctx.arc(x, y, model.innerRadius - pixelMargin, endAngle + angleMargin, startAngle - angleMargin, true); + ctx.arc(x, y, outerRadius, startAngle - angleMargin, endAngle + angleMargin); + if (innerRadius > pixelMargin) { + angleMargin = pixelMargin / innerRadius; + ctx.arc(x, y, innerRadius, endAngle + angleMargin, startAngle - angleMargin, true); } else { ctx.arc(x, y, pixelMargin, endAngle + Math.PI / 2, startAngle - Math.PI / 2); } @@ -22,60 +22,73 @@ function clipArc(ctx, model) { } -function pathArc(ctx, model) { +function pathArc(ctx, element) { + const {x, y, startAngle, endAngle, pixelMargin} = element; + const outerRadius = Math.max(element.outerRadius - pixelMargin, 0); + const innerRadius = element.innerRadius + pixelMargin; + ctx.beginPath(); - ctx.arc(model.x, model.y, model.outerRadius, model.startAngle, model.endAngle); - ctx.arc(model.x, model.y, model.innerRadius, model.endAngle, model.startAngle, true); + ctx.arc(x, y, outerRadius, startAngle, endAngle); + ctx.arc(x, y, innerRadius, endAngle, startAngle, true); ctx.closePath(); } -function drawArc(ctx, model, circumference) { - if (model.fullCircles) { - model.endAngle = model.startAngle + TAU; +function drawArc(ctx, element) { + if (element.fullCircles) { + element.endAngle = element.startAngle + TAU; - pathArc(ctx, model); + pathArc(ctx, element); - for (let i = 0; i < model.fullCircles; ++i) { + for (let i = 0; i < element.fullCircles; ++i) { ctx.fill(); } - model.endAngle = model.startAngle + circumference % TAU; + element.endAngle = element.startAngle + element.circumference % TAU; } - pathArc(ctx, model); + pathArc(ctx, element); ctx.fill(); } -function drawFullCircleBorders(ctx, element, model, inner) { - const endAngle = model.endAngle; +function drawFullCircleBorders(ctx, element, inner) { + const {x, y, startAngle, endAngle, pixelMargin} = element; + const outerRadius = Math.max(element.outerRadius - pixelMargin, 0); + const innerRadius = element.innerRadius + pixelMargin; + let i; if (inner) { - model.endAngle = model.startAngle + TAU; - clipArc(ctx, model); - model.endAngle = endAngle; - if (model.endAngle === model.startAngle && model.fullCircles) { - model.endAngle += TAU; - model.fullCircles--; + element.endAngle = element.startAngle + TAU; + clipArc(ctx, element); + element.endAngle = endAngle; + if (element.endAngle === element.startAngle) { + element.endAngle += TAU; + element.fullCircles--; } } ctx.beginPath(); - ctx.arc(model.x, model.y, model.innerRadius, model.startAngle + TAU, model.startAngle, true); - for (i = 0; i < model.fullCircles; ++i) { + ctx.arc(x, y, innerRadius, startAngle + TAU, startAngle, true); + for (i = 0; i < element.fullCircles; ++i) { ctx.stroke(); } ctx.beginPath(); - ctx.arc(model.x, model.y, element.outerRadius, model.startAngle, model.startAngle + TAU); - for (i = 0; i < model.fullCircles; ++i) { + ctx.arc(x, y, outerRadius, startAngle, startAngle + TAU); + for (i = 0; i < element.fullCircles; ++i) { ctx.stroke(); } } -function drawBorder(ctx, element, model) { - const options = element.options; +function drawBorder(ctx, element) { + const {x, y, startAngle, endAngle, pixelMargin, options} = element; + const outerRadius = element.outerRadius; + const innerRadius = element.innerRadius + pixelMargin; const inner = options.borderAlign === 'inner'; + if (!options.borderWidth) { + return; + } + if (inner) { ctx.lineWidth = options.borderWidth * 2; ctx.lineJoin = 'round'; @@ -84,17 +97,17 @@ function drawBorder(ctx, element, model) { ctx.lineJoin = 'bevel'; } - if (model.fullCircles) { - drawFullCircleBorders(ctx, element, model, inner); + if (element.fullCircles) { + drawFullCircleBorders(ctx, element, inner); } if (inner) { - clipArc(ctx, model); + clipArc(ctx, element); } ctx.beginPath(); - ctx.arc(model.x, model.y, element.outerRadius, model.startAngle, model.endAngle); - ctx.arc(model.x, model.y, model.innerRadius, model.endAngle, model.startAngle, true); + ctx.arc(x, y, outerRadius, startAngle, endAngle); + ctx.arc(x, y, innerRadius, endAngle, startAngle, true); ctx.closePath(); ctx.stroke(); } @@ -110,6 +123,8 @@ export default class Arc extends Element { this.endAngle = undefined; this.innerRadius = undefined; this.outerRadius = undefined; + this.pixelMargin = 0; + this.fullCircles = 0; if (cfg) { Object.assign(this, cfg); @@ -167,32 +182,26 @@ export default class Arc extends Element { draw(ctx) { const me = this; const options = me.options; - const pixelMargin = (options.borderAlign === 'inner') ? 0.33 : 0; - const model = { - x: me.x, - y: me.y, - innerRadius: me.innerRadius, - outerRadius: Math.max(me.outerRadius - pixelMargin, 0), - pixelMargin, - startAngle: me.startAngle, - endAngle: me.endAngle, - fullCircles: Math.floor(me.circumference / TAU) - }; + const offset = options.offset || 0; + me.pixelMargin = (options.borderAlign === 'inner') ? 0.33 : 0; + me.fullCircles = Math.floor(me.circumference / TAU); if (me.circumference === 0) { return; } ctx.save(); + if (offset && me.circumference < TAU) { + const halfAngle = (me.startAngle + me.endAngle) / 2; + ctx.translate(Math.cos(halfAngle) * offset, Math.sin(halfAngle) * offset); + } + ctx.fillStyle = options.backgroundColor; ctx.strokeStyle = options.borderColor; - drawArc(ctx, model, me.circumference); - - if (options.borderWidth) { - drawBorder(ctx, me, model); - } + drawArc(ctx, me); + drawBorder(ctx, me); ctx.restore(); } @@ -206,7 +215,8 @@ Arc.id = 'arc'; Arc.defaults = { borderAlign: 'center', borderColor: '#fff', - borderWidth: 2 + borderWidth: 2, + offset: 0 }; /**
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
src/core/core.scale.js
@@ -142,12 +142,12 @@ function getTickMarkLength(options) { /** * @param {object} options */ -function getScaleLabelHeight(options) { +function getScaleLabelHeight(options, fallback) { if (!options.display) { return 0; } - const font = toFont(options.font); + const font = toFont(options.font, fallback); const padding = toPadding(options.padding); return font.lineHeight + padding.height; @@ -673,7 +673,7 @@ export default class Scale extends Element { if (maxLabelWidth + 6 > tickWidth) { tickWidth = maxWidth / (numTicks - (options.offset ? 0.5 : 1)); maxHeight = me.maxHeight - getTickMarkLength(options.gridLines) - - tickOpts.padding - getScaleLabelHeight(options.scaleLabel); + - tickOpts.padding - getScaleLabelHeight(options.scaleLabel, me.chart.options.font); maxLabelDiagonal = Math.sqrt(maxLabelWidth * maxLabelWidth + maxLabelHeight * maxLabelHeight); labelRotation = toDegrees(Math.min( Math.asin(Math.min((labelSizes.highest.height + 6) / tickWidth, 1)), @@ -709,19 +709,20 @@ export default class Scale extends Element { const display = me._isVisible(); const labelsBelowTicks = opts.position !== 'top' && me.axis === 'x'; const isHorizontal = me.isHorizontal(); + const scaleLabelHeight = display && getScaleLabelHeight(scaleLabelOpts, chart.options.font); // Width if (isHorizontal) { minSize.width = me.maxWidth; } else if (display) { - minSize.width = getTickMarkLength(gridLineOpts) + getScaleLabelHeight(scaleLabelOpts); + minSize.width = getTickMarkLength(gridLineOpts) + scaleLabelHeight; } // height if (!isHorizontal) { minSize.height = me.maxHeight; // fill all the height } else if (display) { - minSize.height = getTickMarkLength(gridLineOpts) + getScaleLabelHeight(scaleLabelOpts); + minSize.height = getTickMarkLength(gridLineOpts) + scaleLabelHeight; } // Don't bother fitting the ticks if we are not showing the labels @@ -1460,7 +1461,7 @@ export default class Scale extends Element { return; } - const scaleLabelFont = toFont(scaleLabel.font); + const scaleLabelFont = toFont(scaleLabel.font, me.chart.options.font); const scaleLabelPadding = toPadding(scaleLabel.padding); const halfLineHeight = scaleLabelFont.lineHeight / 2; const scaleLabelAlign = scaleLabel.align; @@ -1594,15 +1595,16 @@ export default class Scale extends Element { */ _resolveTickFontOptions(index) { const me = this; + const chart = me.chart; const options = me.options.ticks; const ticks = me.ticks || []; const context = { - chart: me.chart, + chart, scale: me, tick: ticks[index], index }; - return toFont(resolve([options.font], context)); + return toFont(resolve([options.font], context), chart.options.font); } }
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
src/helpers/helpers.options.js
@@ -67,27 +67,29 @@ export function toPadding(value) { /** * Parses font options and returns the font object. * @param {object} options - A object that contains font options to be parsed. + * @param {object} [fallback] - A object that contains fallback font options. * @return {object} The font object. * @private */ -export function toFont(options) { - const defaultFont = defaults.font; +export function toFont(options, fallback) { options = options || {}; - let size = valueOrDefault(options.size, defaultFont.size); + fallback = fallback || defaults.font; + + let size = valueOrDefault(options.size, fallback.size); if (typeof size === 'string') { size = parseInt(size, 10); } const font = { - color: valueOrDefault(options.color, defaultFont.color), - family: valueOrDefault(options.family, defaultFont.family), - lineHeight: toLineHeight(valueOrDefault(options.lineHeight, defaultFont.lineHeight), size), - lineWidth: valueOrDefault(options.lineWidth, defaultFont.lineWidth), + color: valueOrDefault(options.color, fallback.color), + family: valueOrDefault(options.family, fallback.family), + lineHeight: toLineHeight(valueOrDefault(options.lineHeight, fallback.lineHeight), size), + lineWidth: valueOrDefault(options.lineWidth, fallback.lineWidth), size, - style: valueOrDefault(options.style, defaultFont.style), - weight: valueOrDefault(options.weight, defaultFont.weight), - strokeStyle: valueOrDefault(options.strokeStyle, defaultFont.strokeStyle), + style: valueOrDefault(options.style, fallback.style), + weight: valueOrDefault(options.weight, fallback.weight), + strokeStyle: valueOrDefault(options.strokeStyle, fallback.strokeStyle), string: '' };
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
src/plugins/plugin.legend.js
@@ -178,7 +178,7 @@ export class Legend extends Element { const display = opts.display; const ctx = me.ctx; - const labelFont = toFont(labelOpts.font); + const labelFont = toFont(labelOpts.font, me.chart.options.font); const fontSize = labelFont.size; const boxWidth = getBoxWidth(labelOpts, fontSize); const boxHeight = getBoxHeight(labelOpts, fontSize); @@ -304,7 +304,7 @@ export class Legend extends Element { me.drawTitle(); const rtlHelper = getRtlAdapter(opts.rtl, me.left, me._minSize.width); const ctx = me.ctx; - const labelFont = toFont(labelOpts.font); + const labelFont = toFont(labelOpts.font, me.chart.options.font); const fontColor = labelFont.color; const fontSize = labelFont.size; let cursor; @@ -469,7 +469,7 @@ export class Legend extends Element { const me = this; const opts = me.options; const titleOpts = opts.title; - const titleFont = toFont(titleOpts.font); + const titleFont = toFont(titleOpts.font, me.chart.options.font); const titlePadding = toPadding(titleOpts.padding); if (!titleOpts.display) { @@ -551,7 +551,7 @@ export class Legend extends Element { */ _computeTitleHeight() { const titleOpts = this.options.title; - const titleFont = toFont(titleOpts.font); + const titleFont = toFont(titleOpts.font, this.chart.options.font); const titlePadding = toPadding(titleOpts.padding); return titleOpts.display ? titleFont.lineHeight + titlePadding.height : 0; }
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
src/plugins/plugin.title.js
@@ -107,7 +107,7 @@ export class Title extends Element { const lineCount = isArray(opts.text) ? opts.text.length : 1; me._padding = toPadding(opts.padding); - const textSize = lineCount * toFont(opts.font).lineHeight + me._padding.height; + const textSize = lineCount * toFont(opts.font, me.chart.options.font).lineHeight + me._padding.height; me.width = minSize.width = isHorizontal ? me.maxWidth : textSize; me.height = minSize.height = isHorizontal ? textSize : me.maxHeight; } @@ -130,7 +130,7 @@ export class Title extends Element { return; } - const fontOpts = toFont(opts.font); + const fontOpts = toFont(opts.font, me.chart.options.font); const lineHeight = fontOpts.lineHeight; const offset = lineHeight / 2 + me._padding.top; let rotation = 0;
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
src/plugins/plugin.tooltip.js
@@ -135,14 +135,15 @@ function createTooltipItem(chart, item) { /** * Helper to get the reset model for the tooltip * @param options {object} the tooltip options + * @param fallbackFont {object} the fallback font options */ -function resolveOptions(options) { +function resolveOptions(options, fallbackFont) { options = merge({}, [defaults.plugins.tooltip, options]); - options.bodyFont = toFont(options.bodyFont); - options.titleFont = toFont(options.titleFont); - options.footerFont = toFont(options.footerFont); + options.bodyFont = toFont(options.bodyFont, fallbackFont); + options.titleFont = toFont(options.titleFont, fallbackFont); + options.footerFont = toFont(options.footerFont, fallbackFont); options.boxHeight = valueOrDefault(options.boxHeight, options.bodyFont.size); options.boxWidth = valueOrDefault(options.boxWidth, options.bodyFont.size); @@ -388,7 +389,8 @@ export class Tooltip extends Element { initialize() { const me = this; - me.options = resolveOptions(me._chart.options.tooltips); + const chartOpts = me._chart.options; + me.options = resolveOptions(chartOpts.tooltips, chartOpts.font); } /** @@ -1114,5 +1116,5 @@ export default { footer: noop, afterFooter: noop } - } + }, };
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
src/scales/scale.radialLinear.js
@@ -102,7 +102,7 @@ function fitWithPointLabels(scale) { index: i, label: scale.pointLabels[i] }; - const plFont = toFont(resolve([scale.options.pointLabels.font], context, i)); + const plFont = toFont(resolve([scale.options.pointLabels.font], context, i), scale.chart.options.font); scale.ctx.font = plFont.string; textSize = measureLabelSize(scale.ctx, plFont.lineHeight, scale.pointLabels[i]); scale._pointLabelSizes[i] = textSize; @@ -191,7 +191,7 @@ function drawPointLabels(scale) { index: i, label: scale.pointLabels[i], }; - const plFont = toFont(resolve([pointLabelOpts.font], context, i)); + const plFont = toFont(resolve([pointLabelOpts.font], context, i), scale.chart.options.font); ctx.font = plFont.string; ctx.fillStyle = plFont.color;
true
Other
chartjs
Chart.js
e756fb93a3b8cb5a29de04d9bcf972295e38b21f.json
Resolve fonts through options.font (#7674) * Resolve fonts through options.font * Remove defaultRoutes from Tooltip fonts
test/specs/plugin.title.tests.js
@@ -19,7 +19,9 @@ describe('Title block tests', function() { }); it('should update correctly', function() { - var chart = {}; + var chart = { + options: Chart.helpers.clone(Chart.defaults) + }; var options = Chart.helpers.clone(Chart.defaults.plugins.title); options.text = 'My title'; @@ -44,7 +46,9 @@ describe('Title block tests', function() { }); it('should update correctly when vertical', function() { - var chart = {}; + var chart = { + options: Chart.helpers.clone(Chart.defaults) + }; var options = Chart.helpers.clone(Chart.defaults.plugins.title); options.text = 'My title'; @@ -70,7 +74,9 @@ describe('Title block tests', function() { }); it('should have the correct size when there are multiple lines of text', function() { - var chart = {}; + var chart = { + options: Chart.helpers.clone(Chart.defaults) + }; var options = Chart.helpers.clone(Chart.defaults.plugins.title); options.text = ['line1', 'line2']; @@ -90,7 +96,9 @@ describe('Title block tests', function() { }); it('should draw correctly horizontally', function() { - var chart = {}; + var chart = { + options: Chart.helpers.clone(Chart.defaults) + }; var context = window.createMockContext(); var options = Chart.helpers.clone(Chart.defaults.plugins.title); @@ -142,7 +150,9 @@ describe('Title block tests', function() { }); it ('should draw correctly vertically', function() { - var chart = {}; + var chart = { + options: Chart.helpers.clone(Chart.defaults) + }; var context = window.createMockContext(); var options = Chart.helpers.clone(Chart.defaults.plugins.title);
true
Other
chartjs
Chart.js
da0764a585db495c18f2f450f8b3cb32a68b374e.json
Fix casing of dist files in docs (#7670)
.github/ISSUE_TEMPLATE/BUG.md
@@ -32,7 +32,7 @@ labels: 'type: bug' interactive example (https://codepen.io/pen?template=JXVYzq). If filing a bug against `master`, you may reference the latest code via - https://www.chartjs.org/dist/master/Chart.min.js (changing the filename to + https://www.chartjs.org/dist/master/chart.min.js (changing the filename to point at the file you need as appropriate). Do not rely on these files for production purposes as they may be removed at any time. -->
true
Other
chartjs
Chart.js
da0764a585db495c18f2f450f8b3cb32a68b374e.json
Fix casing of dist files in docs (#7670)
docs/docs/developers/contributing.md
@@ -78,6 +78,6 @@ Guidelines for reporting bugs: - Check the issue search to see if it has already been reported - Isolate the problem to a simple test case -- Please include a demonstration of the bug on a website such as [JS Bin](https://jsbin.com/), [JS Fiddle](https://jsfiddle.net/), or [Codepen](https://codepen.io/pen/). ([Template](https://codepen.io/pen?template=JXVYzq)). If filing a bug against `master`, you may reference the latest code via <https://www.chartjs.org/dist/master/Chart.min.js> (changing the filename to point at the file you need as appropriate). Do not rely on these files for production purposes as they may be removed at any time. +- Please include a demonstration of the bug on a website such as [JS Bin](https://jsbin.com/), [JS Fiddle](https://jsfiddle.net/), or [Codepen](https://codepen.io/pen/). ([Template](https://codepen.io/pen?template=JXVYzq)). If filing a bug against `master`, you may reference the latest code via <https://www.chartjs.org/dist/master/chart.min.js> (changing the filename to point at the file you need as appropriate). Do not rely on these files for production purposes as they may be removed at any time. Please provide any additional details associated with the bug, if it's browser or screen density specific, or only happens with a certain configuration or data.
true
Other
chartjs
Chart.js
da0764a585db495c18f2f450f8b3cb32a68b374e.json
Fix casing of dist files in docs (#7670)
docs/docs/developers/index.md
@@ -8,26 +8,27 @@ Developer features allow extending and enhancing Chart.js in many different ways Latest documentation and samples, including unreleased features, are available at: - - https://www.chartjs.org/docs/master/ - - https://www.chartjs.org/samples/master/ +- https://www.chartjs.org/docs/master/ +- https://www.chartjs.org/samples/master/ ## Development releases Latest builds are available for testing at: - - https://www.chartjs.org/dist/master/Chart.js - - https://www.chartjs.org/dist/master/Chart.min.js +- https://www.chartjs.org/dist/master/chart.js +- https://www.chartjs.org/dist/master/chart.min.js **WARNING: Development builds MUST not be used for production purposes or as replacement for CDN.** ## Browser support Chart.js offers support for the following browsers: -* Chrome 50+ -* Firefox 45+ -* Internet Explorer 11 -* Edge 14+ -* Safari 9+ + +- Chrome 50+ +- Firefox 45+ +- Internet Explorer 11 +- Edge 14+ +- Safari 9+ Browser support for the canvas element is available in all modern & major mobile browsers. [CanIUse](https://caniuse.com/#feat=canvas)
true
Other
chartjs
Chart.js
bdef29ebb10b2d8d7f2689ee5038433a01f8b8a2.json
Fix import statement in docs (#7653)
docs/docs/getting-started/integration.md
@@ -25,7 +25,7 @@ var myChart = new Chart(ctx, {...}); Chart.js 3 is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use. ```javascript -import Chart, LineController, Line, Point, LinearScale, CategoryScale, Title, Tooltip, Filler, Legend from 'chart.js'; +import { Chart, LineController, Line, Point, LinearScale, CategoryScale, Title, Tooltip, Filler, Legend } from 'chart.js'; Chart.register(LineController, Line, Point, LinearScale, CategoryScale, Title, Tooltip, Filler, Legend);
true
Other
chartjs
Chart.js
bdef29ebb10b2d8d7f2689ee5038433a01f8b8a2.json
Fix import statement in docs (#7653)
docs/docs/getting-started/v3-migration.md
@@ -24,7 +24,7 @@ Chart.js 3.0 introduces a number of breaking changes. Chart.js 2.0 was released * Chart.js 3 is tree-shakeable. So if you are using it as an `npm` module in a project, you need to import and register the controllers, elements, scales and plugins you want to use. You will not have to call `register` if importing Chart.js via a `script` tag, but will not get the tree shaking benefits in this case. Here is an example of registering components: ```javascript -import Chart, LineController, Line, Point, LinearScale, Title from `chart.js` +import { Chart, LineController, Line, Point, LinearScale, Title } from `chart.js` Chart.register(LineController, Line, Point, LinearScale, Title);
true
Other
chartjs
Chart.js
843829f16c5d8bde57c4ae7cf60a43a68d0c0b95.json
Fix tooltip in financial sample (#7638)
samples/scales/financial.html
@@ -39,7 +39,7 @@ </select> <button id="update">update</button> <script> - // Generate data between the stock market hours of 9:30am - 5pm. + // Generate data between the stock market hours of 9:30am - 4pm. // This method is slow and unoptimized, but in real life we'd be fetching it from the server. function generateData() { const unit = document.getElementById('unit').value; @@ -54,7 +54,7 @@ function after4pm(date) { - return date.hour > 16 || (date.hour === 16 && date.minute > 0); + return date.hour >= 16; } // Returns true if outside 9:30am-4pm on a weekday @@ -191,7 +191,7 @@ if (label) { label += ': '; } - label += parseFloat(context.value).toFixed(2); + label += context.dataPoint.y.toFixed(2); return label; } }
false
Other
chartjs
Chart.js
2564e708b55fe2f032c9e5ee4d00874baa089a9e.json
Determine unit automatically in test (#7637)
test/fixtures/scale.timeseries/financial-daily.js
@@ -34,9 +34,6 @@ module.exports = { maxRotation: 0, sampleSize: 100 }, - time: { - unit: 'month' - }, // manually set major ticks so that test passes in all time zones with moment adapter afterBuildTicks: function(scale) { const major = [0, 12, 24];
false
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
docs/docs/configuration/tooltip.md
@@ -197,7 +197,10 @@ The tooltip items passed to the tooltip callbacks implement the following interf datasetIndex: number, // Index of this data item in the dataset - dataIndex: number + dataIndex: number, + + // The chart element (point, arc, bar, etc.) for this tooltip item + element: Element, } ``` @@ -271,8 +274,7 @@ var myPieChart = new Chart(ctx, { tableRoot.innerHTML = innerHtml; } - // `this` will be the overall tooltip - var position = this._chart.canvas.getBoundingClientRect(); + var position = context.chart.canvas.getBoundingClientRect(); // Display, position, and set styles for font tooltipEl.style.opacity = 1;
true
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
docs/docs/getting-started/v3-migration.md
@@ -342,7 +342,7 @@ The following properties and methods were removed: * Legend `onClick`, `onHover`, and `onLeave` options now receive the legend as the 3rd argument in addition to implicitly via `this` * Legend `onClick`, `onHover`, and `onLeave` options now receive a wrapped `event` as the first parameter. The previous first parameter value is accessible via `event.native`. * `Title.margins` is now private -* The tooltip item's `x` and `y` attributes were removed. Use `datasetIndex` and `dataIndex` to get the element and any corresponding data from it +* The tooltip item's `x` and `y` attributes were replaced by `element`. You can use `element.x` and `element.y` or `element.tooltipPosition()` instead. #### Removal of private APIs
true
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
samples/animations/loop.html
@@ -62,17 +62,16 @@ }] }, options: { - animation: (context) => { - if (context.active) { - return { - radius: { - duration: 400, - loop: true - } - }; + animation: (context) => Object.assign({}, + Chart.defaults.animation, + { + radius: { + duration: 400, + easing: 'linear', + loop: context.active + } } - return Chart.defaults.animation; - }, + ), elements: { point: { hoverRadius: 6
true
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
samples/tooltips/custom-line.html
@@ -160,6 +160,7 @@ tooltips: { enabled: false, mode: 'index', + intersect: false, position: 'nearest', custom: customTooltips }
true
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
samples/tooltips/custom-points.html
@@ -59,14 +59,15 @@ if (tooltip.dataPoints.length > 0) { tooltip.dataPoints.forEach(function(dataPoint) { - var content = [dataPoint.label, dataPoint.value].join(': '); + var content = [dataPoint.label, dataPoint.formattedValue].join(': '); var $tooltip = $('#tooltip-' + dataPoint.datasetIndex); + var pos = dataPoint.element.tooltipPosition(); $tooltip.html(content); $tooltip.css({ opacity: 1, - top: positionY + dataPoint.y + 'px', - left: positionX + dataPoint.x + 'px', + top: positionY + pos.y + 'px', + left: positionX + pos.x + 'px', }); }); }
true
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
src/core/core.animation.js
@@ -50,6 +50,7 @@ export default class Animation { const remain = me._duration - elapsed; me._start = date; me._duration = Math.floor(Math.max(remain, cfg.duration)); + me._loop = !!cfg.loop; me._to = resolve([cfg.to, to, currentValue, cfg.from]); me._from = resolve([cfg.from, currentValue, to]); }
true
Other
chartjs
Chart.js
af855d7646eed442b049c87dcd3c150099203a66.json
Fix remaining issues in samples (#7625) * Fix remaining issues in samples * Update migration guide * Use element instead * Update tooltip.md
src/plugins/plugin.tooltip.js
@@ -112,23 +112,23 @@ function splitNewlines(str) { /** * Private helper to create a tooltip item model - * @param item - the chart element (point, arc, bar) to create the tooltip item for + * @param item - {element, index, datasetIndex} to create the tooltip item for * @return new tooltip item */ function createTooltipItem(chart, item) { - const {datasetIndex, index} = item; + const {element, datasetIndex, index} = item; const controller = chart.getDatasetMeta(datasetIndex).controller; - const dataset = controller.getDataset(); const {label, value} = controller.getLabelAndValue(index); return { chart, label, dataPoint: controller.getParsed(index), formattedValue: value, - dataset, + dataset: controller.getDataset(), dataIndex: index, - datasetIndex + datasetIndex, + element }; } @@ -403,7 +403,8 @@ export class Tooltip extends Element { } const chart = me._chart; - const opts = chart.options.animation && me.options.animation; + const options = me.options; + const opts = options.enabled && chart.options.animation && options.animation; const animations = new Animations(me._chart, opts); me._cachedAnimations = Object.freeze(animations);
true
Other
laravel
framework
f06af0cdac95815fc1d707c0762639aebf52a165.json
run facade script
src/Illuminate/Support/Facades/Auth.php
@@ -56,6 +56,7 @@ * @method static \Illuminate\Auth\SessionGuard setRequest(\Symfony\Component\HttpFoundation\Request $request) * @method static \Illuminate\Support\Timebox getTimebox() * @method static \Illuminate\Contracts\Auth\Authenticatable authenticate() + * @method static \Illuminate\Auth\SessionGuard forgetUser() * @method static \Illuminate\Contracts\Auth\UserProvider getProvider() * @method static void setProvider(\Illuminate\Contracts\Auth\UserProvider $provider) * @method static void macro(string $name, object|callable $macro)
false
Other
laravel
framework
28d07f051131deb23b6b0c2d1c3a24d6417941b1.json
Add sort option for schedule:list (#45198) * Add sort option for schedule:list Currently, in order to see what's schedule will be run, I need to run schedule:list and eyeball the list to find the relevant ones. This PR adds an option to sort the list by the next due date. Before: ``` php artisan schedule:list 0 * * * * php artisan command-one .......... Next Due: 55 minutes from now 15 * * * * php artisan command-three ........ Next Due: 10 minutes from now 17 * * * * php artisan command-two .......... Next Due: 12 minutes from now ``` After: ``` php artisan schedule:list 15 * * * * php artisan command-three ........ Next Due: 10 minutes from now 17 * * * * php artisan command-two .......... Next Due: 12 minutes from now 0 * * * * php artisan command-one .......... Next Due: 55 minutes from now ``` * Add a test * fix styling * need to actually use the flag in the test * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
src/Illuminate/Console/Scheduling/ScheduleListCommand.php
@@ -21,7 +21,10 @@ class ScheduleListCommand extends Command * * @var string */ - protected $signature = 'schedule:list {--timezone= : The timezone that times should be displayed in}'; + protected $signature = 'schedule:list + {--timezone= : The timezone that times should be displayed in} + {--next : Sort the listed tasks by their next due date} + '; /** * The name of the console command. @@ -39,7 +42,7 @@ class ScheduleListCommand extends Command * * @var string */ - protected $description = 'List the scheduled commands'; + protected $description = 'List all scheduled tasks'; /** * The terminal width resolver callback. @@ -72,6 +75,8 @@ public function handle(Schedule $schedule) $timezone = new DateTimeZone($this->option('timezone') ?? config('app.timezone')); + $events = $this->sortEvents($events, $timezone); + $events = $events->map(function ($event) use ($terminalWidth, $expressionSpacing, $timezone) { $expression = $this->formatCronExpression($event->expression, $expressionSpacing); @@ -98,10 +103,7 @@ public function handle(Schedule $schedule) $nextDueDateLabel = 'Next Due:'; - $nextDueDate = Carbon::create((new CronExpression($event->expression)) - ->getNextRunDate(Carbon::now()->setTimezone($event->timezone)) - ->setTimezone($timezone) - ); + $nextDueDate = $this->getNextDueDateForEvent($event, $timezone); $nextDueDate = $this->output->isVerbose() ? $nextDueDate->format('Y-m-d H:i:s P') @@ -150,6 +152,36 @@ private function getCronExpressionSpacing($events) return collect($rows[0] ?? [])->keys()->map(fn ($key) => $rows->max($key)); } + /** + * Sorts the events by due date if option set. + * + * @param \Illuminate\Support\Collection $events + * @param \DateTimeZone $timezone + * @return \Illuminate\Support\Collection + */ + private function sortEvents(\Illuminate\Support\Collection $events, DateTimeZone $timezone) + { + return $this->option('next') + ? $events->sortBy(fn ($event) => $this->getNextDueDateForEvent($event, $timezone)) + : $events; + } + + /** + * Get the next due date for an event. + * + * @param \Illuminate\Console\Scheduling\Event $event + * @param \DateTimeZone $timezone + * @return \Illuminate\Support\Carbon + */ + private function getNextDueDateForEvent($event, DateTimeZone $timezone) + { + return Carbon::create( + (new CronExpression($event->expression)) + ->getNextRunDate(Carbon::now()->setTimezone($event->timezone)) + ->setTimezone($timezone) + ); + } + /** * Formats the cron expression based on the spacing provided. *
true
Other
laravel
framework
28d07f051131deb23b6b0c2d1c3a24d6417941b1.json
Add sort option for schedule:list (#45198) * Add sort option for schedule:list Currently, in order to see what's schedule will be run, I need to run schedule:list and eyeball the list to find the relevant ones. This PR adds an option to sort the list by the next due date. Before: ``` php artisan schedule:list 0 * * * * php artisan command-one .......... Next Due: 55 minutes from now 15 * * * * php artisan command-three ........ Next Due: 10 minutes from now 17 * * * * php artisan command-two .......... Next Due: 12 minutes from now ``` After: ``` php artisan schedule:list 15 * * * * php artisan command-three ........ Next Due: 10 minutes from now 17 * * * * php artisan command-two .......... Next Due: 12 minutes from now 0 * * * * php artisan command-one .......... Next Due: 55 minutes from now ``` * Add a test * fix styling * need to actually use the flag in the test * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
tests/Integration/Console/Scheduling/ScheduleListCommandTest.php
@@ -52,6 +52,30 @@ public function testDisplaySchedule() ->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now'); } + public function testDisplayScheduleWithSort() + { + $this->schedule->command(FooCommand::class)->quarterly(); + $this->schedule->command('inspire')->twiceDaily(14, 18); + $this->schedule->command('foobar', ['a' => 'b'])->everyMinute(); + $this->schedule->job(FooJob::class)->everyMinute(); + $this->schedule->command('inspire')->cron('0 9,17 * * *'); + $this->schedule->command('inspire')->cron("0 10\t* * *"); + + $this->schedule->call(fn () => '')->everyMinute(); + $closureLineNumber = __LINE__ - 1; + $closureFilePath = __FILE__; + + $this->artisan(ScheduleListCommand::class, ['--next' => true]) + ->assertSuccessful() + ->expectsOutput(' * * * * * php artisan foobar a='.ProcessUtils::escapeArgument('b').' ... Next Due: 1 minute from now') + ->expectsOutput(' * * * * * Illuminate\Tests\Integration\Console\Scheduling\FooJob Next Due: 1 minute from now') + ->expectsOutput(' * * * * * Closure at: '.$closureFilePath.':'.$closureLineNumber.' Next Due: 1 minute from now') + ->expectsOutput(' 0 9,17 * * * php artisan inspire ......... Next Due: 9 hours from now') + ->expectsOutput(' 0 10 * * * php artisan inspire ........ Next Due: 10 hours from now') + ->expectsOutput(' 0 14,18 * * * php artisan inspire ........ Next Due: 14 hours from now') + ->expectsOutput(' 0 0 1 1-12/3 * php artisan foo:command .... Next Due: 3 months from now'); + } + public function testDisplayScheduleInVerboseMode() { $this->schedule->command(FooCommand::class)->everyMinute();
true
Other
laravel
framework
fbd39d9ec0f045262874488865e03a9d3c593fd5.json
Apply fixes from StyleCI
src/Illuminate/Routing/AbstractRouteCollection.php
@@ -136,6 +136,7 @@ protected function requestMethodNotAllowed($request, array $others, $method) * @param array $others * @param string $method * @return void + * * @deprecated use requestMethodNotAllowed * * @throws \Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
false
Other
laravel
framework
8ec69f85f90433d15c1afbbd7329700fe601635e.json
Add missing docblock
src/Illuminate/Support/Facades/Bus.php
@@ -43,6 +43,7 @@ class Bus extends Facade * Replace the bound instance with a fake. * * @param array|string $jobsToFake + * @param \Illuminate\Bus\BatchRepository|null $batchRepository * @return \Illuminate\Support\Testing\Fakes\BusFake */ public static function fake($jobsToFake = [], BatchRepository $batchRepository = null)
false
Other
laravel
framework
73685ff12821f7491c506bc78e91b0c917dfa75a.json
Add forgetUser() method to GuardHelpers
src/Illuminate/Auth/GuardHelpers.php
@@ -95,6 +95,16 @@ public function setUser(AuthenticatableContract $user) return $this; } + /** + * Forget the user. + * + * @return void + */ + public function forgetUser() + { + $this->user = null; + } + /** * Get the user provider used by the guard. *
true
Other
laravel
framework
73685ff12821f7491c506bc78e91b0c917dfa75a.json
Add forgetUser() method to GuardHelpers
src/Illuminate/Support/Facades/Auth.php
@@ -56,6 +56,7 @@ * @method static \Illuminate\Auth\SessionGuard setRequest(\Symfony\Component\HttpFoundation\Request $request) * @method static \Illuminate\Support\Timebox getTimebox() * @method static \Illuminate\Contracts\Auth\Authenticatable authenticate() + * @method static void forgetUser() * @method static \Illuminate\Contracts\Auth\UserProvider getProvider() * @method static void setProvider(\Illuminate\Contracts\Auth\UserProvider $provider) * @method static void macro(string $name, object|callable $macro)
true
Other
laravel
framework
73685ff12821f7491c506bc78e91b0c917dfa75a.json
Add forgetUser() method to GuardHelpers
tests/Auth/AuthGuardTest.php
@@ -588,6 +588,14 @@ public function testLoginOnceFailure() $this->assertFalse($guard->once(['foo'])); } + public function testForgetUserSetsUserToNull() + { + $user = m::mock(Authenticatable::class); + $guard = $this->getGuard()->setUser($user); + $guard->forgetUser(); + $this->assertNull($guard->getUser()); + } + protected function getGuard() { [$session, $provider, $request, $cookie, $timebox] = $this->getMocks();
true
Other
laravel
framework
2407c9b86cda499eb2eedb9d19510cb4554fae1c.json
Allow BusFake to use custom BusRepository
src/Illuminate/Support/Facades/Bus.php
@@ -2,6 +2,7 @@ namespace Illuminate\Support\Facades; +use Illuminate\Bus\BatchRepository; use Illuminate\Contracts\Bus\Dispatcher as BusDispatcherContract; use Illuminate\Foundation\Bus\PendingChain; use Illuminate\Support\Testing\Fakes\BusFake; @@ -44,9 +45,9 @@ class Bus extends Facade * @param array|string $jobsToFake * @return \Illuminate\Support\Testing\Fakes\BusFake */ - public static function fake($jobsToFake = []) + public static function fake($jobsToFake = [], BatchRepository $batchRepository = null) { - static::swap($fake = new BusFake(static::getFacadeRoot(), $jobsToFake)); + static::swap($fake = new BusFake(static::getFacadeRoot(), $jobsToFake, $batchRepository)); return $fake; }
true
Other
laravel
framework
2407c9b86cda499eb2eedb9d19510cb4554fae1c.json
Allow BusFake to use custom BusRepository
src/Illuminate/Support/Testing/Fakes/BusFake.php
@@ -3,6 +3,7 @@ namespace Illuminate\Support\Testing\Fakes; use Closure; +use Illuminate\Bus\BatchRepository; use Illuminate\Bus\PendingBatch; use Illuminate\Contracts\Bus\QueueingDispatcher; use Illuminate\Support\Arr; @@ -75,13 +76,14 @@ class BusFake implements QueueingDispatcher * * @param \Illuminate\Contracts\Bus\QueueingDispatcher $dispatcher * @param array|string $jobsToFake + * @param BatchRepository|null $jobsToFake * @return void */ - public function __construct(QueueingDispatcher $dispatcher, $jobsToFake = []) + public function __construct(QueueingDispatcher $dispatcher, $jobsToFake = [], BatchRepository $batchRepository = null) { $this->dispatcher = $dispatcher; $this->jobsToFake = Arr::wrap($jobsToFake); - $this->batchRepository = new BatchRepositoryFake; + $this->batchRepository = $batchRepository ?: new BatchRepositoryFake; } /**
true
Other
laravel
framework
2407c9b86cda499eb2eedb9d19510cb4554fae1c.json
Allow BusFake to use custom BusRepository
tests/Support/SupportTestingBusFakeTest.php
@@ -5,6 +5,7 @@ use Illuminate\Bus\Batch; use Illuminate\Bus\Queueable; use Illuminate\Contracts\Bus\QueueingDispatcher; +use Illuminate\Support\Testing\Fakes\BatchRepositoryFake; use Illuminate\Support\Testing\Fakes\BusFake; use Mockery as m; use PHPUnit\Framework\Constraint\ExceptionMessage; @@ -28,6 +29,20 @@ protected function tearDown(): void m::close(); } + public function testItUsesCustomBusRepository() + { + $busRepository = new BatchRepositoryFake; + + $fake = new BusFake(m::mock(QueueingDispatcher::class), [], $busRepository); + + $this->assertNull($fake->findBatch('non-existent-batch')); + + $batch = $fake->batch([])->dispatch(); + + $this->assertSame($batch, $fake->findBatch($batch->id)); + $this->assertSame($batch, $busRepository->find($batch->id)); + } + public function testAssertDispatched() { try {
true
Other
laravel
framework
68a9ff343125412dadddb7bf35f88ab42b90f1a9.json
Update InteractsWithQueue::$job PHPDoc (#45195) InteractsWithQueue::$job is a nullable property
src/Illuminate/Queue/InteractsWithQueue.php
@@ -9,7 +9,7 @@ trait InteractsWithQueue /** * The underlying queue job instance. * - * @var \Illuminate\Contracts\Queue\Job + * @var \Illuminate\Contracts\Queue\Job|null */ public $job;
false
Other
laravel
framework
fe3d1bff07215c4ca79a0ae202d15ba22f17318d.json
Update HandleExceptions::$reservedMemory (#45199) HandleExceptions::$reservedMemory is a nullable property
src/Illuminate/Foundation/Bootstrap/HandleExceptions.php
@@ -17,7 +17,7 @@ class HandleExceptions /** * Reserved memory so that errors can be displayed properly on memory exhaustion. * - * @var string + * @var string|null */ public static $reservedMemory;
false
Other
laravel
framework
c32c4fb35f3e1cd75ff2ad1630754712a7e0c6f3.json
add missing reserved names (#45149)
src/Illuminate/Console/GeneratorCommand.php
@@ -60,6 +60,7 @@ abstract class GeneratorCommand extends Command 'eval', 'exit', 'extends', + 'false', 'final', 'finally', 'fn', @@ -93,6 +94,7 @@ abstract class GeneratorCommand extends Command 'switch', 'throw', 'trait', + 'true', 'try', 'unset', 'use',
false
Other
laravel
framework
5b2a3793bea91c07369cdba457695ddf9ac54ad3.json
Fix separator for Windows OS
tests/Console/Scheduling/EventTest.php
@@ -101,7 +101,7 @@ public function testCustomMutexName() $event = new Event(m::mock(EventMutex::class), 'php -i'); $event->description('Fancy command description'); - $this->assertSame('framework/schedule-eeb46c93d45e928d62aaf684d727e213b7094822', $event->mutexName()); + $this->assertSame('framework'.DIRECTORY_SEPARATOR.'schedule-eeb46c93d45e928d62aaf684d727e213b7094822', $event->mutexName()); $event->createMutexNameUsing(function (Event $event) { return Str::slug($event->description);
false
Other
laravel
framework
cfc3433880a6cea6bcb93251e63ff101979456c3.json
Apply fixes from StyleCI
src/Illuminate/Queue/Events/WorkerStopping.php
@@ -2,8 +2,6 @@ namespace Illuminate\Queue\Events; -use Illuminate\Queue\WorkerOptions; - class WorkerStopping { /**
false
Other
laravel
framework
b150ec691074e99a23506e4c9a3c5d6e1792e5a8.json
Add missing space
src/Illuminate/Console/Scheduling/Event.php
@@ -954,7 +954,7 @@ public function mutexName() /** * Set the mutex name resolver callback. * - * @param \Closure $callback + * @param \Closure $callback * @return $this */ public function createMutexNameUsing(Closure $callback)
false
Other
laravel
framework
437e1f0668f94000f2c7ce0abcf774f00c30ce9d.json
Remove unused variable (#45096) * Remove * fix
src/Illuminate/Console/Scheduling/ScheduleWorkCommand.php
@@ -44,7 +44,7 @@ public function handle() { $this->components->info('Running schedule tasks every minute.'); - [$lastExecutionStartedAt, $keyOfLastExecutionWithOutput, $executions] = [null, null, []]; + [$lastExecutionStartedAt, $executions] = [null, []]; while (true) { usleep(100 * 1000);
false
Other
laravel
framework
44ae14d12d4b6ee719b9a1f40d30cd174af62041.json
fix space (#45104)
src/Illuminate/Foundation/Http/Middleware/HandlePrecognitiveRequests.php
@@ -12,7 +12,7 @@ class HandlePrecognitiveRequests { /** - *The container instance. + * The container instance. * * @var \Illuminate\Container\Container */
false
Other
laravel
framework
e19dbdbd840cc0accbb843a6cb1b781b425f2901.json
Add whenMissing() (#45019)
src/Illuminate/Http/Concerns/InteractsWithInput.php
@@ -224,6 +224,27 @@ public function missing($key) return ! $this->has($keys); } + /** + * Apply the callback if the request is missing the given input item key. + * + * @param string $key + * @param callable $callback + * @param callable|null $default + * @return $this|mixed + */ + public function whenMissing($key, callable $callback, callable $default = null) + { + if ($this->missing($key)) { + return $callback(data_get($this->all(), $key)) ?: $this; + } + + if ($default) { + return $default(); + } + + return $this; + } + /** * Determine if the given input key is an empty string for "has". *
true
Other
laravel
framework
e19dbdbd840cc0accbb843a6cb1b781b425f2901.json
Add whenMissing() (#45019)
tests/Http/HttpRequestTest.php
@@ -452,6 +452,41 @@ public function testMissingMethod() $this->assertFalse($request->missing('foo.baz')); } + public function testWhenMissingMethod() + { + $request = Request::create('/', 'GET', ['bar' => null]); + + $name = $age = $city = $foo = $bar = true; + + $request->whenMissing('name', function ($value) use (&$name) { + $name = 'Taylor'; + }); + + $request->whenMissing('age', function ($value) use (&$age) { + $age = ''; + }); + + $request->whenMissing('city', function ($value) use (&$city) { + $city = null; + }); + + $request->whenMissing('foo', function () use (&$foo) { + $foo = false; + }); + + $request->whenMissing('bar', function () use (&$bar) { + $bar = 'test'; + }, function () use (&$bar) { + $bar = true; + }); + + $this->assertSame('Taylor', $name); + $this->assertSame('', $age); + $this->assertNull($city); + $this->assertFalse($foo); + $this->assertTrue($bar); + } + public function testHasAnyMethod() { $request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => '', 'city' => null]);
true
Other
laravel
framework
a3cdcbf3561e69dd999108295d919fb37dfbbb45.json
Apply fixes from StyleCI
src/Illuminate/Validation/Rules/NotIn.php
@@ -6,7 +6,7 @@ class NotIn { /** * The name of the rule. - * + * * @var string */ protected $rule = 'not_in';
false
Other
laravel
framework
64f11a3412d37b00f2bdbc2d3dda1d35cb9fccb5.json
Apply fixes from StyleCI
src/Illuminate/Validation/Rules/In.php
@@ -6,7 +6,7 @@ class In { /** * The name of the rule. - * + * * @var string */ protected $rule = 'in';
false
Other
laravel
framework
7bade4f486e7b600cc9a5d527fcfd85ead1e17db.json
add fix method
src/Illuminate/Support/Lottery.php
@@ -201,6 +201,18 @@ public static function alwaysLose($callback = null) static::determineResultNormally(); } + /** + * Set the sequence that will be used to determine lottery results. + * + * @param array $sequence + * @param callable|null $whenMissing + * @return void + */ + public static function fix($sequence, $whenMissing = null) + { + return static::forceResultWithSequence($sequence, $whenMissing); + } + /** * Set the sequence that will be used to determine lottery results. *
false
Other
laravel
framework
5df600fec62a9f32d633ca0c2e453eafd24d0757.json
Apply fixes from StyleCI
tests/Http/Middleware/TrimStringsTest.php
@@ -9,14 +9,14 @@ class TrimStringsTest extends TestCase { /** - * Test no zero-width space character returns the same string + * Test no zero-width space character returns the same string. */ public function test_no_zero_width_space_character_returns_the_same_string() { $request = new Request; $request->merge([ - 'title' => 'This title does not contains any zero-width space' + 'title' => 'This title does not contains any zero-width space', ]); $middleware = new TrimStrings; @@ -27,14 +27,14 @@ public function test_no_zero_width_space_character_returns_the_same_string() } /** - * Test leading zero-width space character is trimmed [ZWSP] + * Test leading zero-width space character is trimmed [ZWSP]. */ public function test_leading_zero_width_space_character_is_trimmed() { $request = new Request; $request->merge([ - 'title' => '​This title contains a zero-width space at the begining' + 'title' => '​This title contains a zero-width space at the begining', ]); $middleware = new TrimStrings; @@ -45,14 +45,14 @@ public function test_leading_zero_width_space_character_is_trimmed() } /** - * Test trailing zero-width space character is trimmed [ZWSP] + * Test trailing zero-width space character is trimmed [ZWSP]. */ public function test_trailing_zero_width_space_character_is_trimmed() { $request = new Request; $request->merge([ - 'title' => 'This title contains a zero-width space at the end​' + 'title' => 'This title contains a zero-width space at the end​', ]); $middleware = new TrimStrings; @@ -63,14 +63,14 @@ public function test_trailing_zero_width_space_character_is_trimmed() } /** - * Test leading zero-width non-breakable space character is trimmed [ZWNBSP] + * Test leading zero-width non-breakable space character is trimmed [ZWNBSP]. */ public function test_leading_zero_width_non_breakable_space_character_is_trimmed() { $request = new Request; $request->merge([ - 'title' => 'This title contains a zero-width non-breakable space at the begining' + 'title' => 'This title contains a zero-width non-breakable space at the begining', ]); $middleware = new TrimStrings; @@ -81,14 +81,14 @@ public function test_leading_zero_width_non_breakable_space_character_is_trimmed } /** - * Test leading multiple zero-width non-breakable space characters are trimmed [ZWNBSP] + * Test leading multiple zero-width non-breakable space characters are trimmed [ZWNBSP]. */ public function test_leading_multiple_zero_width_non_breakable_space_characters_are_trimmed() { $request = new Request; $request->merge([ - 'title' => 'This title contains a zero-width non-breakable space at the begining' + 'title' => 'This title contains a zero-width non-breakable space at the begining', ]); $middleware = new TrimStrings; @@ -99,14 +99,14 @@ public function test_leading_multiple_zero_width_non_breakable_space_characters_ } /** - * Test a combination of leading and trailing zero-width non-breakable space and zero-width space characters are trimmed [ZWNBSP], [ZWSP] + * Test a combination of leading and trailing zero-width non-breakable space and zero-width space characters are trimmed [ZWNBSP], [ZWSP]. */ public function test_combination_of_leading_and_trailing_zero_width_non_breakable_space_and_zero_width_space_characters_are_trimmed() { $request = new Request; $request->merge([ - 'title' => '​This title contains a zero-width non-breakable space at the end​' + 'title' => '​This title contains a zero-width non-breakable space at the end​', ]); $middleware = new TrimStrings;
false
Other
laravel
framework
937498ba1aa6f97d2c47d685435db9eca1460829.json
Apply fixes from StyleCI
src/Illuminate/Foundation/Console/ShowModelCommand.php
@@ -242,6 +242,7 @@ protected function getObservers($model) // Format listeners Eloquent verb => Observer methods... $extractVerb = function ($key) { preg_match('/eloquent.([a-zA-Z]+)\: /', $key, $matches); + return $matches[1] ?? '?'; };
false
Other
laravel
framework
01a1474aa2fad999902b606efaa214dd7d607178.json
Apply fixes from StyleCI
src/Illuminate/Foundation/Vite.php
@@ -576,7 +576,7 @@ public function reactRefresh() } $attributes = $this->parseAttributes([ - 'nonce' => $this->cspNonce() + 'nonce' => $this->cspNonce(), ]); return new HtmlString(
false
Other
laravel
framework
9fed2b4a323d9fb74f37d735fadd8f058b0aa37f.json
Fix `InteractsWithContainer::withoutMix` (#44822) * Fix InteractsWithContainer::withoutMix Original `mix()` returns `HtmlString` instance, fake-mix should return the same in case if a developer uses `toHtml()` explicitly. E.g.: ```php mix('asset.css')->toHtml() ``` * Update assertion to reflect new withoutMix() behaviour
src/Illuminate/Foundation/Testing/Concerns/InteractsWithContainer.php
@@ -5,6 +5,7 @@ use Closure; use Illuminate\Foundation\Mix; use Illuminate\Foundation\Vite; +use Illuminate\Support\HtmlString; use Mockery; trait InteractsWithContainer @@ -186,7 +187,7 @@ protected function withoutMix() } $this->swap(Mix::class, function () { - return ''; + return new HtmlString(''); }); return $this;
true
Other
laravel
framework
9fed2b4a323d9fb74f37d735fadd8f058b0aa37f.json
Fix `InteractsWithContainer::withoutMix` (#44822) * Fix InteractsWithContainer::withoutMix Original `mix()` returns `HtmlString` instance, fake-mix should return the same in case if a developer uses `toHtml()` explicitly. E.g.: ```php mix('asset.css')->toHtml() ``` * Update assertion to reflect new withoutMix() behaviour
tests/Foundation/Testing/Concerns/InteractsWithContainerTest.php
@@ -49,7 +49,7 @@ public function testWithoutMixBindsEmptyHandlerAndReturnsInstance() { $instance = $this->withoutMix(); - $this->assertSame('', mix('path/to/asset.png')); + $this->assertSame('', (string) mix('path/to/asset.png')); $this->assertSame($this, $instance); }
true
Other
laravel
framework
c2a1fcf81a6a1791575c86e3c68ecf01e5efe077.json
Apply fixes from StyleCI
tests/Notifications/NotificationSendQueuedNotificationTest.php
@@ -56,7 +56,8 @@ public function testSerializationOfNormalNotifiable() public function testNotificationCanSetMaxExceptions() { $notifiable = new NotifiableUser; - $notification = new class { + $notification = new class + { public $maxExceptions = 23; };
false
Other
laravel
framework
78104e0530c930a5585bbc5250d63502b115e207.json
add source file to Collection's dd function output
src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php
@@ -56,12 +56,17 @@ public function resolveDumpSource() $sourceKey = null; foreach ($trace as $traceKey => $traceFile) { - if (isset($traceFile['file']) && str_ends_with( - $traceFile['file'], - 'dump.php' - )) { + if (! isset($traceFile['file'])) { + continue; + } + + if (str_ends_with($traceFile['file'], 'dump.php')) { $sourceKey = $traceKey + 1; + break; + } + if (str_ends_with($traceFile['file'], 'EnumeratesValues.php')) { + $sourceKey = $traceKey + 4; break; } }
false
Other
laravel
framework
9a1ac305d4aaac772f12243aad2c84f19d774081.json
Add touchQuietly convenience method (#44722)
src/Illuminate/Database/Eloquent/Concerns/HasTimestamps.php
@@ -43,6 +43,17 @@ public function touch($attribute = null) return $this->save(); } + /** + * Update the model's update timestamp without raising any events. + * + * @param string|null $attribute + * @return bool + */ + public function touchQuietly($attribute = null) + { + return static::withoutEvents(fn () => $this->touch($attribute)); + } + /** * Update the creation and update timestamps. *
false
Other
laravel
framework
a299816674a5ef99092f6c2d9ed9973a77e4faa4.json
Move Observers below Relations in command output
src/Illuminate/Foundation/Console/ShowModelCommand.php
@@ -352,17 +352,6 @@ protected function displayCli($class, $database, $table, $attributes, $relations $this->newLine(); - $this->components->twoColumnDetail('<fg=green;options=bold>Eloquent Observers</>'); - - if ($observers->count()) { - foreach ($observers as $observer) { - $this->components->twoColumnDetail( - sprintf('%s', $observer['event']), implode(', ', $observer['observer'])); - } - } - - $this->newLine(); - $this->components->twoColumnDetail('<fg=green;options=bold>Relations</>'); foreach ($relations as $relation) { @@ -373,6 +362,17 @@ protected function displayCli($class, $database, $table, $attributes, $relations } $this->newLine(); + + $this->components->twoColumnDetail('<fg=green;options=bold>Observers</>'); + + if ($observers->count()) { + foreach ($observers as $observer) { + $this->components->twoColumnDetail( + sprintf('%s', $observer['event']), implode(', ', $observer['observer'])); + } + } + + $this->newLine(); } /**
false
Other
laravel
framework
23195b44d9ffde5517f6562cb5b1d87b8c9c731d.json
Fix expectations for output assertions. 🧪 (#44723)
src/Illuminate/Testing/PendingCommand.php
@@ -419,6 +419,8 @@ private function createABufferedOutputMock() foreach ($this->test->expectedOutputSubstrings as $i => $text) { $mock->shouldReceive('doWrite') + ->atLeast() + ->times(0) ->withArgs(fn ($output) => str_contains($output, $text)) ->andReturnUsing(function () use ($i) { unset($this->test->expectedOutputSubstrings[$i]); @@ -427,6 +429,8 @@ private function createABufferedOutputMock() foreach ($this->test->unexpectedOutput as $output => $displayed) { $mock->shouldReceive('doWrite') + ->atLeast() + ->times(0) ->ordered() ->with($output, Mockery::any()) ->andReturnUsing(function () use ($output) { @@ -436,6 +440,8 @@ private function createABufferedOutputMock() foreach ($this->test->unexpectedOutputSubstrings as $text => $displayed) { $mock->shouldReceive('doWrite') + ->atLeast() + ->times(0) ->withArgs(fn ($output) => str_contains($output, $text)) ->andReturnUsing(function () use ($text) { $this->test->unexpectedOutputSubstrings[$text] = true;
false
Other
laravel
framework
470f0dadb35e6f9e80c39ac9051ef6931909ae07.json
Apply fixes from StyleCI
src/Illuminate/Foundation/Vite.php
@@ -262,15 +262,15 @@ public function __invoke($entrypoints, $buildDirectory = null) $chunk['src'], $this->assetPath("{$buildDirectory}/{$chunk['file']}"), $chunk, - $manifest + $manifest, ]); foreach ($chunk['imports'] ?? [] as $import) { $preloads->push([ $import, $this->assetPath("{$buildDirectory}/{$manifest[$import]['file']}"), $manifest[$import], - $manifest + $manifest, ]); foreach ($manifest[$import]['css'] ?? [] as $css) { @@ -280,7 +280,7 @@ public function __invoke($entrypoints, $buildDirectory = null) $partialManifest->keys()->first(), $this->assetPath("{$buildDirectory}/{$css}"), $partialManifest->first(), - $manifest + $manifest, ]); $tags->push($this->makeTagForChunk( @@ -306,7 +306,7 @@ public function __invoke($entrypoints, $buildDirectory = null) $partialManifest->keys()->first(), $this->assetPath("{$buildDirectory}/{$css}"), $partialManifest->first(), - $manifest + $manifest, ]); $tags->push($this->makeTagForChunk(
true
Other
laravel
framework
470f0dadb35e6f9e80c39ac9051ef6931909ae07.json
Apply fixes from StyleCI
tests/Http/Middleware/VitePreloadingTest.php
@@ -21,7 +21,8 @@ protected function tearDown(): void public function testItDoesNotSetLinkTagWhenNoTagsHaveBeenPreloaded() { $app = new Container(); - $app->instance(Vite::class, new class extends Vite { + $app->instance(Vite::class, new class extends Vite + { protected $preloadedAssets = []; }); Facade::setFacadeApplication($app); @@ -36,7 +37,8 @@ public function testItDoesNotSetLinkTagWhenNoTagsHaveBeenPreloaded() public function testItAddsPreloadLinkHeader() { $app = new Container(); - $app->instance(Vite::class, new class extends Vite { + $app->instance(Vite::class, new class extends Vite + { protected $preloadedAssets = [ 'https://laravel.com/app.js' => [ 'rel="modulepreload"',
true
Other
laravel
framework
fa6e2f025f61e813de537043f693ea02f661a3e4.json
Remove return types Since we don't add return types like this right now, it's best to keep things consistent.
src/Illuminate/Filesystem/FilesystemAdapter.php
@@ -562,7 +562,7 @@ public function size($path) * * @throws UnableToProvideChecksum */ - public function checksum(string $path, array $options = []): string|false + public function checksum(string $path, array $options = []) { try { return $this->driver->checksum($path, $options);
false
Other
laravel
framework
a45a89479af426e758e5e963457dc4d17dcea9a1.json
Apply fixes from StyleCI
tests/Integration/Database/EloquentPivotTest.php
@@ -46,14 +46,14 @@ public function testPivotConvenientHelperReturnExpectedResult() $project->contributors()->attach($user); $project->collaborators()->attach($user2); - tap($project->contributors->first()->pivot, function ($pivot) use ($project, $user) { + tap($project->contributors->first()->pivot, function ($pivot) { $this->assertEquals(1, $pivot->getKey()); $this->assertEquals(1, $pivot->getQueueableId()); $this->assertSame('user_id', $pivot->getRelatedKey()); $this->assertSame('project_id', $pivot->getForeignKey()); }); - tap($project->collaborators->first()->pivot, function ($pivot) use ($project, $user2) { + tap($project->collaborators->first()->pivot, function ($pivot) { $this->assertNull($pivot->getKey()); $this->assertSame('project_id:1:user_id:2', $pivot->getQueueableId()); $this->assertSame('user_id', $pivot->getRelatedKey());
false
Other
laravel
framework
fd3fe72e2ab0ad4c312696418fcc0e260311b664.json
Set phpredis to latest (#44667)
.github/workflows/tests.yml
@@ -52,7 +52,7 @@ jobs: uses: shivammathur/setup-php@v2 with: php-version: ${{ matrix.php }} - extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis-phpredis/phpredis@5.3.5, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp + extensions: dom, curl, libxml, mbstring, zip, pcntl, pdo, sqlite, pdo_sqlite, gd, redis-phpredis/phpredis@5.3.7, igbinary, msgpack, lzf, zstd, lz4, memcached, gmp ini-values: error_reporting=E_ALL tools: composer:v2 coverage: none
false
Other
laravel
framework
3b26f7a1ef2f04a3c1dfd6454eed4385e2399152.json
Add event TransactionCommitting (#44608)
src/Illuminate/Database/Concerns/ManagesTransactions.php
@@ -43,6 +43,7 @@ public function transaction(Closure $callback, $attempts = 1) try { if ($this->transactions == 1) { + $this->fireConnectionEvent('committing'); $this->getPdo()->commit(); } @@ -188,7 +189,8 @@ protected function handleBeginTransactionException(Throwable $e) */ public function commit() { - if ($this->transactions == 1) { + if ($this->transactionLevel() == 1) { + $this->fireConnectionEvent('committing'); $this->getPdo()->commit(); }
true
Other
laravel
framework
3b26f7a1ef2f04a3c1dfd6454eed4385e2399152.json
Add event TransactionCommitting (#44608)
src/Illuminate/Database/Connection.php
@@ -13,6 +13,7 @@ use Illuminate\Database\Events\StatementPrepared; use Illuminate\Database\Events\TransactionBeginning; use Illuminate\Database\Events\TransactionCommitted; +use Illuminate\Database\Events\TransactionCommitting; use Illuminate\Database\Events\TransactionRolledBack; use Illuminate\Database\Query\Builder as QueryBuilder; use Illuminate\Database\Query\Expression; @@ -978,6 +979,7 @@ protected function fireConnectionEvent($event) return $this->events?->dispatch(match ($event) { 'beganTransaction' => new TransactionBeginning($this), 'committed' => new TransactionCommitted($this), + 'committing' => new TransactionCommitting($this), 'rollingBack' => new TransactionRolledBack($this), default => null, });
true
Other
laravel
framework
3b26f7a1ef2f04a3c1dfd6454eed4385e2399152.json
Add event TransactionCommitting (#44608)
src/Illuminate/Database/Events/TransactionCommitting.php
@@ -0,0 +1,8 @@ +<?php + +namespace Illuminate\Database\Events; + +class TransactionCommitting extends ConnectionEvent +{ + // +}
true
Other
laravel
framework
3b26f7a1ef2f04a3c1dfd6454eed4385e2399152.json
Add event TransactionCommitting (#44608)
tests/Database/DatabaseConnectionTest.php
@@ -10,6 +10,7 @@ use Illuminate\Database\Events\QueryExecuted; use Illuminate\Database\Events\TransactionBeginning; use Illuminate\Database\Events\TransactionCommitted; +use Illuminate\Database\Events\TransactionCommitting; use Illuminate\Database\Events\TransactionRolledBack; use Illuminate\Database\MultipleColumnsSelectedException; use Illuminate\Database\Query\Builder as BaseBuilder; @@ -247,6 +248,18 @@ public function testCommittedFiresEventsIfSet() $connection->commit(); } + public function testCommittingFiresEventsIfSet() + { + $pdo = $this->createMock(DatabaseConnectionTestMockPDO::class); + $connection = $this->getMockConnection(['getName', 'transactionLevel'], $pdo); + $connection->expects($this->any())->method('getName')->willReturn('name'); + $connection->expects($this->any())->method('transactionLevel')->willReturn(1); + $connection->setEventDispatcher($events = m::mock(Dispatcher::class)); + $events->shouldReceive('dispatch')->once()->with(m::type(TransactionCommitting::class)); + $events->shouldReceive('dispatch')->once()->with(m::type(TransactionCommitted::class)); + $connection->commit(); + } + public function testRollBackedFiresEventsIfSet() { $pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
true
Other
laravel
framework
faf384276ee437c556eabc1fed4c6262ce8103d2.json
fix mail tags silently failing (#44550)
src/Illuminate/View/Compilers/ComponentTagCompiler.php
@@ -236,8 +236,12 @@ protected function componentString(string $component, array $attributes) // component and pass the component as a view parameter to the data so it // can be accessed within the component and we can render out the view. if (! class_exists($class)) { + $view = Str::startsWith($component, 'mail::') + ? "\$__env->getContainer()->make(Illuminate\\View\\Factory::class)->make('{$component}')" + : "'$class'"; + $parameters = [ - 'view' => "'$class'", + 'view' => $view, 'data' => '['.$this->attributesToString($data->all(), $escapeBound = false).']', ];
false
Other
laravel
framework
c703de37d6eee632a3eb661c2866566fda80388e.json
add TestResponse::assertContent() (#44580)
src/Illuminate/Testing/TestResponse.php
@@ -514,6 +514,19 @@ public function getCookie($cookieName, $decrypt = true, $unserialize = false) } } + /** + * Assert that the given string matches the response content. + * + * @param string $value + * @return $this + */ + public function assertContent($value) + { + PHPUnit::assertSame($value, $this->content()); + + return $this; + } + /** * Assert that the given string or array of strings are contained within the response. *
true
Other
laravel
framework
c703de37d6eee632a3eb661c2866566fda80388e.json
add TestResponse::assertContent() (#44580)
tests/Testing/TestResponseTest.php
@@ -211,6 +211,29 @@ public function testAssertViewMissingNested() $response->assertViewMissing('foo.baz'); } + public function testAssertContent() + { + $response = $this->makeMockResponse([ + 'render' => 'expected response data', + ]); + + $response->assertContent('expected response data'); + + try { + $response->assertContent('expected'); + $this->fail('xxxx'); + } catch (AssertionFailedError $e) { + $this->assertSame('Failed asserting that two strings are identical.', $e->getMessage()); + } + + try { + $response->assertContent('expected response data with extra'); + $this->fail('xxxx'); + } catch (AssertionFailedError $e) { + $this->assertSame('Failed asserting that two strings are identical.', $e->getMessage()); + } + } + public function testAssertSee() { $response = $this->makeMockResponse([
true
Other
laravel
framework
a1611c76ffd9221978378f361af00fac2fe0b4aa.json
Apply fixes from StyleCI
tests/Mail/MailMailableTest.php
@@ -991,7 +991,6 @@ public function build() public function testAssertHasSubject() { - } }
false
Other
laravel
framework
4bc8737955c01a7e04b0fd47e84cd16ac42acba3.json
add mailable assertions (#44563) * add mailable assertions * formatting * formatting * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
src/Illuminate/Mail/Mailable.php
@@ -1147,6 +1147,149 @@ public function hasMetadata($key, $value) (method_exists($this, 'envelope') && $this->envelope()->hasMetadata($key, $value)); } + /** + * Assert that the mailable is from the given address. + * + * @param object|array|string $address + * @param string|null $name + * @return $this + */ + public function assertFrom($address, $name = null) + { + $recipient = $this->formatAssertionRecipient($address, $name); + + PHPUnit::assertTrue( + $this->hasFrom($address, $name), + "Email was not from expected address [{$recipient}]." + ); + + return $this; + } + + /** + * Assert that the mailable has the given recipient. + * + * @param object|array|string $address + * @param string|null $name + * @return $this + */ + public function assertTo($address, $name = null) + { + $recipient = $this->formatAssertionRecipient($address, $name); + + PHPUnit::assertTrue( + $this->hasTo($address, $name), + "Did not see expected recipient [{$recipient}] in email recipients." + ); + + return $this; + } + + /** + * Assert that the mailable has the given recipient. + * + * @param object|array|string $address + * @param string|null $name + * @return $this + */ + public function assertHasTo($address, $name = null) + { + return $this->assertTo($address, $name); + } + + /** + * Assert that the mailable has the given recipient. + * + * @param object|array|string $address + * @param string|null $name + * @return $this + */ + public function assertHasCc($address, $name = null) + { + $recipient = $this->formatAssertionRecipient($address, $name); + + PHPUnit::assertTrue( + $this->hasCc($address, $name), + "Did not see expected recipient [{$recipient}] in email recipients." + ); + + return $this; + } + + /** + * Assert that the mailable has the given recipient. + * + * @param object|array|string $address + * @param string|null $name + * @return $this + */ + public function assertHasBcc($address, $name = null) + { + $recipient = $this->formatAssertionRecipient($address, $name); + + PHPUnit::assertTrue( + $this->hasBcc($address, $name), + "Did not see expected recipient [{$recipient}] in email recipients." + ); + + return $this; + } + + /** + * Assert that the mailable has the given "reply to" address. + * + * @param object|array|string $address + * @param string|null $name + * @return $this + */ + public function assertHasReplyTo($address, $name = null) + { + $replyTo = $this->formatAssertionRecipient($address, $name); + + PHPUnit::assertTrue( + $this->hasReplyTo($address, $name), + "Did not see expected address [{$replyTo}] as email 'reply to' recipient." + ); + + return $this; + } + + /** + * Format the mailable recipeint for display in an assertion message. + * + * @param object|array|string $address + * @param string|null $name + * @return string + */ + private function formatAssertionRecipient($address, $name = null) + { + if (! is_string($address)) { + $address = json_encode($address); + } + + if (filled($name)) { + $address .= ' ('.$name.')'; + } + + return $address; + } + + /** + * Assert that the mailable has the given subject. + * + * @param string $subject + * @return $this + */ + public function assertHasSubject($subject) + { + PHPUnit::assertTrue( + $this->hasSubject($subject), + "Did not see expected text [{$subject}] in email subject." + ); + + return $this; + } + /** * Assert that the given text is present in the HTML email body. * @@ -1329,6 +1472,39 @@ public function assertHasAttachmentFromStorageDisk($disk, $path, $name = null, a return $this; } + /** + * Assert that the mailable has the given tag. + * + * @param string $tag + * @return $this + */ + public function assertHasTag($tag) + { + PHPUnit::assertTrue( + $this->hasTag($tag), + "Did not see expected tag [{$tag}] in email tags." + ); + + return $this; + } + + /** + * Assert that the mailable has the given metadata. + * + * @param string $key + * @param string $value + * @return $this + */ + public function assertHasMetadata($key, $value) + { + PHPUnit::assertTrue( + $this->hasMetadata($key, $value), + "Did not see expected key [{$key}] and value [{$value}] in email metadata." + ); + + return $this; + } + /** * Render the HTML and plain-text version of the mailable into views for assertions. *
true
Other
laravel
framework
4bc8737955c01a7e04b0fd47e84cd16ac42acba3.json
add mailable assertions (#44563) * add mailable assertions * formatting * formatting * formatting Co-authored-by: Taylor Otwell <taylor@laravel.com>
tests/Mail/MailMailableTest.php
@@ -26,36 +26,49 @@ public function testMailableSetsRecipientsCorrectly() $mailable->to('taylor@laravel.com'); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->to); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); + $mailable->assertHasTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->to('taylor@laravel.com', 'Taylor Otwell'); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->to); $this->assertTrue($mailable->hasTo('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); + $mailable->assertHasTo('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertHasTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->to(['taylor@laravel.com']); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->to); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); $this->assertFalse($mailable->hasTo('taylor@laravel.com', 'Taylor Otwell')); + $mailable->assertHasTo('taylor@laravel.com'); + try { + $mailable->assertHasTo('taylor@laravel.com', 'Taylor Otwell'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Did not see expected recipient [taylor@laravel.com (Taylor Otwell)] in email recipients.\nFailed asserting that false is true.", $e->getMessage()); + } $mailable = new WelcomeMailableStub; $mailable->to([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->to); $this->assertTrue($mailable->hasTo('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); + $mailable->assertHasTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->to(new MailableTestUserStub); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->to); $this->assertTrue($mailable->hasTo(new MailableTestUserStub)); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); + $mailable->assertHasTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->to(collect([new MailableTestUserStub])); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->to); $this->assertTrue($mailable->hasTo(new MailableTestUserStub)); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); + $mailable->assertHasTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->to(collect([new MailableTestUserStub, new MailableTestUserStub])); @@ -65,12 +78,22 @@ public function testMailableSetsRecipientsCorrectly() ], $mailable->to); $this->assertTrue($mailable->hasTo(new MailableTestUserStub)); $this->assertTrue($mailable->hasTo('taylor@laravel.com')); + $mailable->assertHasTo('taylor@laravel.com'); foreach (['', null, [], false] as $address) { $mailable = new WelcomeMailableStub; $mailable->to($address); $this->assertFalse($mailable->hasTo(new MailableTestUserStub)); $this->assertFalse($mailable->hasTo($address)); + try { + $mailable->assertHasTo($address); + $this->fail(); + } catch (AssertionFailedError $e) { + if (! is_string($address)) { + $address = json_encode($address); + } + $this->assertSame("Did not see expected recipient [{$address}] in email recipients.\nFailed asserting that false is true.", $e->getMessage()); + } } } @@ -80,36 +103,50 @@ public function testMailableSetsCcRecipientsCorrectly() $mailable->cc('taylor@laravel.com'); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->cc); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->cc('taylor@laravel.com', 'Taylor Otwell'); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc); $this->assertTrue($mailable->hasCc('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertHasCc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->cc(['taylor@laravel.com']); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->cc); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); $this->assertFalse($mailable->hasCc('taylor@laravel.com', 'Taylor Otwell')); + $mailable->assertHasCc('taylor@laravel.com'); + try { + $mailable->assertHasCc('taylor@laravel.com', 'Taylor Otwell'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Did not see expected recipient [taylor@laravel.com (Taylor Otwell)] in email recipients.\nFailed asserting that false is true.", $e->getMessage()); + } $mailable = new WelcomeMailableStub; $mailable->cc([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc); $this->assertTrue($mailable->hasCc('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertHasCc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->cc(new MailableTestUserStub); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc); $this->assertTrue($mailable->hasCc(new MailableTestUserStub)); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->cc(collect([new MailableTestUserStub])); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->cc); $this->assertTrue($mailable->hasCc(new MailableTestUserStub)); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->cc(collect([new MailableTestUserStub, new MailableTestUserStub])); @@ -119,6 +156,7 @@ public function testMailableSetsCcRecipientsCorrectly() ], $mailable->cc); $this->assertTrue($mailable->hasCc(new MailableTestUserStub)); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->cc(['taylor@laravel.com', 'not-taylor@laravel.com']); @@ -128,12 +166,23 @@ public function testMailableSetsCcRecipientsCorrectly() ], $mailable->cc); $this->assertTrue($mailable->hasCc('taylor@laravel.com')); $this->assertTrue($mailable->hasCc('not-taylor@laravel.com')); + $mailable->assertHasCc('taylor@laravel.com'); + $mailable->assertHasCc('not-taylor@laravel.com'); foreach (['', null, [], false] as $address) { $mailable = new WelcomeMailableStub; $mailable->cc($address); $this->assertFalse($mailable->hasCc(new MailableTestUserStub)); $this->assertFalse($mailable->hasCc($address)); + try { + $mailable->assertHasCc($address); + $this->fail(); + } catch (AssertionFailedError $e) { + if (! is_string($address)) { + $address = json_encode($address); + } + $this->assertSame("Did not see expected recipient [{$address}] in email recipients.\nFailed asserting that false is true.", $e->getMessage()); + } } } @@ -143,36 +192,50 @@ public function testMailableSetsBccRecipientsCorrectly() $mailable->bcc('taylor@laravel.com'); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->bcc); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->bcc('taylor@laravel.com', 'Taylor Otwell'); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc); $this->assertTrue($mailable->hasBcc('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertHasBcc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->bcc(['taylor@laravel.com']); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->bcc); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); $this->assertFalse($mailable->hasBcc('taylor@laravel.com', 'Taylor Otwell')); + $mailable->assertHasBcc('taylor@laravel.com'); + try { + $mailable->assertHasBcc('taylor@laravel.com', 'Taylor Otwell'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Did not see expected recipient [taylor@laravel.com (Taylor Otwell)] in email recipients.\nFailed asserting that false is true.", $e->getMessage()); + } $mailable = new WelcomeMailableStub; $mailable->bcc([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc); $this->assertTrue($mailable->hasBcc('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertHasBcc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->bcc(new MailableTestUserStub); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc); $this->assertTrue($mailable->hasBcc(new MailableTestUserStub)); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->bcc(collect([new MailableTestUserStub])); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->bcc); $this->assertTrue($mailable->hasBcc(new MailableTestUserStub)); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->bcc(collect([new MailableTestUserStub, new MailableTestUserStub])); @@ -182,6 +245,7 @@ public function testMailableSetsBccRecipientsCorrectly() ], $mailable->bcc); $this->assertTrue($mailable->hasBcc(new MailableTestUserStub)); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->bcc(['taylor@laravel.com', 'not-taylor@laravel.com']); @@ -191,12 +255,23 @@ public function testMailableSetsBccRecipientsCorrectly() ], $mailable->bcc); $this->assertTrue($mailable->hasBcc('taylor@laravel.com')); $this->assertTrue($mailable->hasBcc('not-taylor@laravel.com')); + $mailable->assertHasBcc('taylor@laravel.com'); + $mailable->assertHasBcc('not-taylor@laravel.com'); foreach (['', null, [], false] as $address) { $mailable = new WelcomeMailableStub; $mailable->bcc($address); $this->assertFalse($mailable->hasBcc(new MailableTestUserStub)); $this->assertFalse($mailable->hasBcc($address)); + try { + $mailable->assertHasBcc($address); + $this->fail(); + } catch (AssertionFailedError $e) { + if (! is_string($address)) { + $address = json_encode($address); + } + $this->assertSame("Did not see expected recipient [{$address}] in email recipients.\nFailed asserting that false is true.", $e->getMessage()); + } } } @@ -206,36 +281,50 @@ public function testMailableSetsReplyToCorrectly() $mailable->replyTo('taylor@laravel.com'); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); + $mailable->assertHasReplyTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->replyTo('taylor@laravel.com', 'Taylor Otwell'); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); + $mailable->assertHasReplyTo('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertHasReplyTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->replyTo(['taylor@laravel.com']); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); $this->assertFalse($mailable->hasReplyTo('taylor@laravel.com', 'Taylor Otwell')); + $mailable->assertHasReplyTo('taylor@laravel.com'); + try { + $mailable->assertHasReplyTo('taylor@laravel.com', 'Taylor Otwell'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Did not see expected address [taylor@laravel.com (Taylor Otwell)] as email 'reply to' recipient.\nFailed asserting that false is true.", $e->getMessage()); + } $mailable = new WelcomeMailableStub; $mailable->replyTo([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); + $mailable->assertHasReplyTo('taylor@laravel.com'); + $mailable->assertHasReplyTo('taylor@laravel.com', 'Taylor Otwell'); $mailable = new WelcomeMailableStub; $mailable->replyTo(new MailableTestUserStub); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo(new MailableTestUserStub)); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); + $mailable->assertHasReplyTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->replyTo(collect([new MailableTestUserStub])); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo(new MailableTestUserStub)); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); + $mailable->assertHasReplyTo('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->replyTo(collect([new MailableTestUserStub, new MailableTestUserStub])); @@ -245,12 +334,22 @@ public function testMailableSetsReplyToCorrectly() ], $mailable->replyTo); $this->assertTrue($mailable->hasReplyTo(new MailableTestUserStub)); $this->assertTrue($mailable->hasReplyTo('taylor@laravel.com')); + $mailable->assertHasReplyTo('taylor@laravel.com'); foreach (['', null, [], false] as $address) { $mailable = new WelcomeMailableStub; $mailable->replyTo($address); $this->assertFalse($mailable->hasReplyTo(new MailableTestUserStub)); $this->assertFalse($mailable->hasReplyTo($address)); + try { + $mailable->assertHasReplyTo($address); + $this->fail(); + } catch (AssertionFailedError $e) { + if (! is_string($address)) { + $address = json_encode($address); + } + $this->assertSame("Did not see expected address [{$address}] as email 'reply to' recipient.\nFailed asserting that false is true.", $e->getMessage()); + } } } @@ -260,36 +359,50 @@ public function testMailableSetsFromCorrectly() $mailable->from('taylor@laravel.com'); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->from); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); + $mailable->assertFrom('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->from('taylor@laravel.com', 'Taylor Otwell'); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->from); $this->assertTrue($mailable->hasFrom('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); + $mailable->assertFrom('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertFrom('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->from(['taylor@laravel.com']); $this->assertEquals([['name' => null, 'address' => 'taylor@laravel.com']], $mailable->from); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); $this->assertFalse($mailable->hasFrom('taylor@laravel.com', 'Taylor Otwell')); + $mailable->assertFrom('taylor@laravel.com'); + try { + $mailable->assertFrom('taylor@laravel.com', 'Taylor Otwell'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Email was not from expected address [taylor@laravel.com (Taylor Otwell)].\nFailed asserting that false is true.", $e->getMessage()); + } $mailable = new WelcomeMailableStub; $mailable->from([['name' => 'Taylor Otwell', 'email' => 'taylor@laravel.com']]); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->from); $this->assertTrue($mailable->hasFrom('taylor@laravel.com', 'Taylor Otwell')); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); + $mailable->assertFrom('taylor@laravel.com', 'Taylor Otwell'); + $mailable->assertFrom('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->from(new MailableTestUserStub); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->from); $this->assertTrue($mailable->hasFrom(new MailableTestUserStub)); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); + $mailable->assertFrom('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->from(collect([new MailableTestUserStub])); $this->assertEquals([['name' => 'Taylor Otwell', 'address' => 'taylor@laravel.com']], $mailable->from); $this->assertTrue($mailable->hasFrom(new MailableTestUserStub)); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); + $mailable->assertFrom('taylor@laravel.com'); $mailable = new WelcomeMailableStub; $mailable->from(collect([new MailableTestUserStub, new MailableTestUserStub])); @@ -299,12 +412,22 @@ public function testMailableSetsFromCorrectly() ], $mailable->from); $this->assertTrue($mailable->hasFrom(new MailableTestUserStub)); $this->assertTrue($mailable->hasFrom('taylor@laravel.com')); + $mailable->assertFrom('taylor@laravel.com'); foreach (['', null, [], false] as $address) { $mailable = new WelcomeMailableStub; $mailable->from($address); $this->assertFalse($mailable->hasFrom(new MailableTestUserStub)); $this->assertFalse($mailable->hasFrom($address)); + try { + $mailable->assertFrom($address); + $this->fail(); + } catch (AssertionFailedError $e) { + if (! is_string($address)) { + $address = json_encode($address); + } + $this->assertSame("Email was not from expected address [{$address}].\nFailed asserting that false is true.", $e->getMessage()); + } } } @@ -476,6 +599,18 @@ public function testMailableMetadataGetsSent() $this->assertSame('hello@laravel.com', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress()); $this->assertStringContainsString('X-Metadata-origin: test-suite', $sentMessage->toString()); $this->assertStringContainsString('X-Metadata-user_id: 1', $sentMessage->toString()); + + $this->assertTrue($mailable->hasMetadata('origin', 'test-suite')); + $this->assertTrue($mailable->hasMetadata('user_id', 1)); + $this->assertFalse($mailable->hasMetadata('test', 'test')); + $mailable->assertHasMetadata('origin', 'test-suite'); + $mailable->assertHasMetadata('user_id', 1); + try { + $mailable->assertHasMetadata('test', 'test'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Did not see expected key [test] and value [test] in email metadata.\nFailed asserting that false is true.", $e->getMessage()); + } } public function testMailableTagGetsSent() @@ -497,6 +632,18 @@ public function testMailableTagGetsSent() $this->assertSame('hello@laravel.com', $sentMessage->getEnvelope()->getRecipients()[0]->getAddress()); $this->assertStringContainsString('X-Tag: test', $sentMessage->toString()); $this->assertStringContainsString('X-Tag: foo', $sentMessage->toString()); + + $this->assertTrue($mailable->hasTag('test')); + $this->assertTrue($mailable->hasTag('foo')); + $this->assertFalse($mailable->hasTag('bar')); + $mailable->assertHasTag('test'); + $mailable->assertHasTag('foo'); + try { + $mailable->assertHasTag('bar'); + $this->fail(); + } catch (AssertionFailedError $e) { + $this->assertSame("Did not see expected tag [bar] in email tags.\nFailed asserting that false is true.", $e->getMessage()); + } } public function testItCanAttachMultipleFiles() @@ -841,6 +988,11 @@ public function build() $mailable->assertHasAttachmentFromStorage('/path/to/foo.jpg'); } + + public function testAssertHasSubject() + { + + } } class WelcomeMailableStub extends Mailable
true
Other
laravel
framework
7f71ec4b23f9e57baa0088ad16b78e7b33c1b34e.json
Add morphUsingUlids to Schema Facade (#44551)
src/Illuminate/Support/Facades/Schema.php
@@ -22,6 +22,7 @@ * @method static array getColumnListing(string $table) * @method static string getColumnType(string $table, string $column) * @method static void morphUsingUuids() + * @method static void morphUsingUlids() * @method static \Illuminate\Database\Connection getConnection() * @method static \Illuminate\Database\Schema\Builder setConnection(\Illuminate\Database\Connection $connection) *
false
Other
laravel
framework
1066e3955bfd0a7877707786efbf4fda9d450502.json
Fix method name in shouldBeStrict method (#44520)
src/Illuminate/Database/Eloquent/Model.php
@@ -398,7 +398,7 @@ public static function shouldBeStrict(bool $shouldBeStrict = true) static::preventLazyLoading(); static::preventSilentlyDiscardingAttributes(); - static::preventsAccessingMissingAttributes(); + static::preventAccessingMissingAttributes(); } /**
false
Other
laravel
framework
ae9a17ea5192baea7dd2ec55167b1e8532f239d3.json
Apply fixes from StyleCI
tests/Support/SupportStringableTest.php
@@ -173,17 +173,17 @@ public function testWhenContainsAll() return $stringable->studly(); })); } - + public function testDirname() { $this->assertSame('/framework/tests', (string) $this->stringable('/framework/tests/Support')->dirname()); $this->assertSame('/framework', (string) $this->stringable('/framework/tests/Support')->dirname(2)); - + $this->assertSame('/', (string) $this->stringable('/framework/')->dirname()); - + $this->assertSame('/', (string) $this->stringable('/')->dirname()); $this->assertSame('.', (string) $this->stringable('.')->dirname()); - + // without slash $this->assertSame('.', (string) $this->stringable('framework')->dirname()); }
false
Other
laravel
framework
b1d86bde040d418f995b6cf920c671275a979a89.json
Add dirname test (#44491)
tests/Support/SupportStringableTest.php
@@ -173,6 +173,20 @@ public function testWhenContainsAll() return $stringable->studly(); })); } + + public function testDirname() + { + $this->assertSame('/framework/tests', (string) $this->stringable('/framework/tests/Support')->dirname()); + $this->assertSame('/framework', (string) $this->stringable('/framework/tests/Support')->dirname(2)); + + $this->assertSame('/', (string) $this->stringable('/framework/')->dirname()); + + $this->assertSame('/', (string) $this->stringable('/')->dirname()); + $this->assertSame('.', (string) $this->stringable('.')->dirname()); + + // without slash + $this->assertSame('.', (string) $this->stringable('framework')->dirname()); + } public function testUcsplitOnStringable() {
false
Other
laravel
framework
b7d97686cf48bb518a997fed4f6ad4a3b5d83a98.json
Apply fixes from StyleCI
tests/Support/SupportStringableTest.php
@@ -948,16 +948,15 @@ public function testPadRight() public function testExplode() { - $this->assertInstanceOf(Collection::class, $this->stringable("Foo Bar Baz")->explode(" ")); - - $this->assertSame('["Foo","Bar","Baz"]', (string) $this->stringable("Foo Bar Baz")->explode(" ")); - - // with limit - $this->assertSame('["Foo","Bar Baz"]', (string) $this->stringable("Foo Bar Baz")->explode(" ", 2)); - $this->assertSame('["Foo","Bar"]', (string) $this->stringable("Foo Bar Baz")->explode(" ", -1)); + $this->assertInstanceOf(Collection::class, $this->stringable('Foo Bar Baz')->explode(' ')); + + $this->assertSame('["Foo","Bar","Baz"]', (string) $this->stringable('Foo Bar Baz')->explode(' ')); + // with limit + $this->assertSame('["Foo","Bar Baz"]', (string) $this->stringable('Foo Bar Baz')->explode(' ', 2)); + $this->assertSame('["Foo","Bar"]', (string) $this->stringable('Foo Bar Baz')->explode(' ', -1)); } - + public function testChunk() { $chunks = $this->stringable('foobarbaz')->split(3);
false
Other
laravel
framework
2e077822e304a1d6bc4cb7681a960dfdd2b71393.json
Add explode test (#44479)
tests/Support/SupportStringableTest.php
@@ -946,6 +946,18 @@ public function testPadRight() $this->assertSame('❤MultiByte☆ ', (string) $this->stringable('❤MultiByte☆')->padRight(16)); } + public function testExplode() + { + $this->assertInstanceOf(Collection::class, $this->stringable("Foo Bar Baz")->explode(" ")); + + $this->assertSame('["Foo","Bar","Baz"]', (string) $this->stringable("Foo Bar Baz")->explode(" ")); + + // with limit + $this->assertSame('["Foo","Bar Baz"]', (string) $this->stringable("Foo Bar Baz")->explode(" ", 2)); + $this->assertSame('["Foo","Bar"]', (string) $this->stringable("Foo Bar Baz")->explode(" ", -1)); + + } + public function testChunk() { $chunks = $this->stringable('foobarbaz')->split(3);
false
Other
laravel
framework
758b805bb99c1ae275ab803346e50f766816d7dd.json
Add test for max and min validation rules (#44444)
tests/Validation/ValidationValidatorTest.php
@@ -2559,12 +2559,28 @@ public function testValidateMin() $v = new Validator($trans, ['foo' => '3'], ['foo' => 'Min:3']); $this->assertFalse($v->passes()); + // an equal value qualifies. + $v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Min:3']); + $this->assertTrue($v->passes()); + $v = new Validator($trans, ['foo' => 'anc'], ['foo' => 'Min:3']); $this->assertTrue($v->passes()); $v = new Validator($trans, ['foo' => '2'], ['foo' => 'Numeric|Min:3']); $this->assertFalse($v->passes()); + // '2.001' is considered as a float when the "Numeric" rule exists. + $v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Numeric|Min:3']); + $this->assertFalse($v->passes()); + + // '2.001' is a string of length 5 in absence of the "Numeric" rule. + $v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Min:3']); + $this->assertTrue($v->passes()); + + // '20' is a string of length 2 in absence of the "Numeric" rule. + $v = new Validator($trans, ['foo' => '20'], ['foo' => 'Min:3']); + $this->assertFalse($v->passes()); + $v = new Validator($trans, ['foo' => '5'], ['foo' => 'Numeric|Min:3']); $this->assertTrue($v->passes()); @@ -2597,6 +2613,18 @@ public function testValidateMax() $v = new Validator($trans, ['foo' => '211'], ['foo' => 'Numeric|Max:100']); $this->assertFalse($v->passes()); + // an equal value qualifies. + $v = new Validator($trans, ['foo' => '3'], ['foo' => 'Numeric|Max:3']); + $this->assertTrue($v->passes()); + + // '2.001' is considered as a float when the "Numeric" rule exists. + $v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Numeric|Max:3']); + $this->assertTrue($v->passes()); + + // '2.001' is a string of length 5 in absence of the "Numeric" rule. + $v = new Validator($trans, ['foo' => '2.001'], ['foo' => 'Max:3']); + $this->assertFalse($v->passes()); + $v = new Validator($trans, ['foo' => '22'], ['foo' => 'Numeric|Max:33']); $this->assertTrue($v->passes());
false
Other
laravel
framework
7f0bc56e29e6e20cd91726e7bbcab65f050dabd4.json
add array type for callback (#44433)
src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
@@ -147,7 +147,7 @@ public function removeObservableEvents($observables) * Register a model event with the dispatcher. * * @param string $event - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ protected static function registerModelEvent($event, $callback) @@ -230,7 +230,7 @@ protected function filterModelEventResults($result) /** * Register a retrieved model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function retrieved($callback) @@ -241,7 +241,7 @@ public static function retrieved($callback) /** * Register a saving model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function saving($callback) @@ -252,7 +252,7 @@ public static function saving($callback) /** * Register a saved model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function saved($callback) @@ -263,7 +263,7 @@ public static function saved($callback) /** * Register an updating model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function updating($callback) @@ -274,7 +274,7 @@ public static function updating($callback) /** * Register an updated model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function updated($callback) @@ -285,7 +285,7 @@ public static function updated($callback) /** * Register a creating model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function creating($callback) @@ -296,7 +296,7 @@ public static function creating($callback) /** * Register a created model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function created($callback) @@ -307,7 +307,7 @@ public static function created($callback) /** * Register a replicating model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function replicating($callback) @@ -318,7 +318,7 @@ public static function replicating($callback) /** * Register a deleting model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function deleting($callback) @@ -329,7 +329,7 @@ public static function deleting($callback) /** * Register a deleted model event with the dispatcher. * - * @param \Illuminate\Events\QueuedClosure|\Closure|string $callback + * @param \Illuminate\Events\QueuedClosure|\Closure|string|array $callback * @return void */ public static function deleted($callback)
false
Other
laravel
framework
5e5bad00d1fa3fb51666e44b77c593422660e85f.json
Fix DB::getPdo() docblock (#44403)
src/Illuminate/Support/Facades/DB.php
@@ -3,7 +3,7 @@ namespace Illuminate\Support\Facades; /** - * @method static \Doctrine\DBAL\Driver\PDOConnection getPdo() + * @method static \PDO getPdo() * @method static \Illuminate\Database\ConnectionInterface connection(string $name = null) * @method static \Illuminate\Database\Query\Builder table(string $table, string $as = null) * @method static \Illuminate\Database\Query\Builder query()
false
Other
laravel
framework
372deaf5b606969efea696cda733121b82fc9eac.json
remove double spaces (#44389) super minor formatting
src/Illuminate/Routing/RouteRegistrar.php
@@ -22,10 +22,10 @@ * @method \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware) * @method \Illuminate\Routing\RouteRegistrar name(string $value) * @method \Illuminate\Routing\RouteRegistrar namespace(string|null $value) - * @method \Illuminate\Routing\RouteRegistrar prefix(string $prefix) + * @method \Illuminate\Routing\RouteRegistrar prefix(string $prefix) * @method \Illuminate\Routing\RouteRegistrar scopeBindings() - * @method \Illuminate\Routing\RouteRegistrar where(array $where) - * @method \Illuminate\Routing\RouteRegistrar withoutMiddleware(array|string $middleware) + * @method \Illuminate\Routing\RouteRegistrar where(array $where) + * @method \Illuminate\Routing\RouteRegistrar withoutMiddleware(array|string $middleware) */ class RouteRegistrar {
true
Other
laravel
framework
372deaf5b606969efea696cda733121b82fc9eac.json
remove double spaces (#44389) super minor formatting
src/Illuminate/Support/Facades/Broadcast.php
@@ -5,7 +5,7 @@ use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactoryContract; /** - * @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(string $channel, callable|string $callback, array $options = []) + * @method static \Illuminate\Broadcasting\Broadcasters\Broadcaster channel(string $channel, callable|string $callback, array $options = []) * @method static \Illuminate\Broadcasting\BroadcastManager socket($request = null) * @method static \Illuminate\Contracts\Broadcasting\Broadcaster connection($name = null); * @method static mixed auth(\Illuminate\Http\Request $request)
true
Other
laravel
framework
372deaf5b606969efea696cda733121b82fc9eac.json
remove double spaces (#44389) super minor formatting
src/Illuminate/Support/Facades/Cache.php
@@ -6,7 +6,7 @@ * @method static \Illuminate\Cache\TaggedCache tags(array|mixed $names) * @method static \Illuminate\Contracts\Cache\Lock lock(string $name, int $seconds = 0, mixed $owner = null) * @method static \Illuminate\Contracts\Cache\Lock restoreLock(string $name, string $owner) - * @method static \Illuminate\Contracts\Cache\Repository store(string|null $name = null) + * @method static \Illuminate\Contracts\Cache\Repository store(string|null $name = null) * @method static \Illuminate\Contracts\Cache\Store getStore() * @method static bool add(string $key, $value, \DateTimeInterface|\DateInterval|int $ttl = null) * @method static bool flush()
true
Other
laravel
framework
1ce080b131b643b9c91bb5f7f1a245f4735879e8.json
use default cipher
src/Illuminate/Foundation/Console/EnvironmentDecryptCommand.php
@@ -78,7 +78,7 @@ public function handle() return Command::FAILURE; } - $cipher = $this->option('cipher') ?: 'aes-128-cbc'; + $cipher = $this->option('cipher') ?: 'AES-256-CBC'; $key = $this->parseKey($key);
true
Other
laravel
framework
1ce080b131b643b9c91bb5f7f1a245f4735879e8.json
use default cipher
src/Illuminate/Foundation/Console/EnvironmentEncryptCommand.php
@@ -67,7 +67,7 @@ public function __construct(Filesystem $files) */ public function handle() { - $cipher = $this->option('cipher') ?: 'aes-128-cbc'; + $cipher = $this->option('cipher') ?: 'AES-256-CBC'; $key = $this->option('key');
true
Other
laravel
framework
278c6d7fd04be005c1175a7eaea868976177600c.json
Apply fixes from StyleCI
src/Illuminate/Support/Benchmark.php
@@ -3,7 +3,6 @@ namespace Illuminate\Support; use Closure; -use Illuminate\Support\Arr; class Benchmark {
false
Other
laravel
framework
b4293d7c18b08b363ac0af64ec04fb1d559b4698.json
add benchmark utility class
src/Illuminate/Support/Benchmark.php
@@ -0,0 +1,47 @@ +<?php + +namespace Illuminate\Support; + +use Closure; +use Illuminate\Support\Arr; + +class Benchmark +{ + /** + * Measure a callable or array of callables over the given number of iterations. + * + * @param \Closure|array $benchmarkables + * @param int $iterations + * @return array|float + */ + public static function measure(Closure|array $benchmarkables, int $iterations = 1): array|float + { + return collect(Arr::wrap($benchmarkables))->map(function ($callback) use ($iterations) { + return collect(range(1, $iterations))->map(function () use ($callback) { + gc_collect_cycles(); + + $start = hrtime(true); + + $callback(); + + return (hrtime(true) - $start) / 1000000; + })->average(); + })->when( + $benchmarkables instanceof Closure, + fn ($c) => $c->first(), + fn ($c) => $c->all(), + ); + } + + /** + * Measure a callable or array of callables over the given number of iterations, then die and dump. + * + * @param \Closure|array $benchmarkables + * @param int $iterations + * @return void + */ + public static function dd(Closure|array $benchmarkables, int $iterations = 1): void + { + dd(static::measure($benchmarkables, $iterations)); + } +}
false
Other
laravel
framework
66d37573dd6017dba1531c8ff9f294b1898351e6.json
Add methods to cast Stringables (#44238)
src/Illuminate/Support/Stringable.php
@@ -3,6 +3,7 @@ namespace Illuminate\Support; use Closure; +use Illuminate\Support\Facades\Date; use Illuminate\Support\Traits\Conditionable; use Illuminate\Support\Traits\Macroable; use Illuminate\Support\Traits\Tappable; @@ -1117,6 +1118,56 @@ public function toString() return $this->value; } + /** + * Get the underlying string value as an integer. + * + * @return int + */ + public function toInteger() + { + return intval($this->value); + } + + /** + * Get the underlying string value as a float. + * + * @return float + */ + public function toFloat() + { + return floatval($this->value); + } + + /** + * Get the underlying string value as a boolean. + * + * Returns true when value is "1", "true", "on", and "yes". Otherwise, returns false. + * + * @return bool + */ + public function toBoolean() + { + return filter_var($this->value, FILTER_VALIDATE_BOOLEAN); + } + + /** + * Get the underlying string value as a Carbon instance. + * + * @param string|null $format + * @param string|null $tz + * @return \Illuminate\Support\Carbon + * + * @throws \Carbon\Exceptions\InvalidFormatException + */ + public function toDate($format = null, $tz = null) + { + if (is_null($format)) { + return Date::parse($this->value, $tz); + } + + return Date::createFromFormat($format, $this->value, $tz); + } + /** * Convert the object to a string when JSON encoded. *
true
Other
laravel
framework
66d37573dd6017dba1531c8ff9f294b1898351e6.json
Add methods to cast Stringables (#44238)
tests/Support/SupportStringableTest.php
@@ -2,6 +2,7 @@ namespace Illuminate\Tests\Support; +use Illuminate\Support\Carbon; use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; use Illuminate\Support\Stringable; @@ -1073,4 +1074,59 @@ public function testExactly() $this->assertFalse($this->stringable('[]')->exactly([])); $this->assertFalse($this->stringable('0')->exactly(0)); } + + public function testToInteger() + { + $this->assertSame(123, $this->stringable('123')->toInteger()); + $this->assertSame(456, $this->stringable(456)->toInteger()); + $this->assertSame(78, $this->stringable('078')->toInteger()); + $this->assertSame(901, $this->stringable(' 901')->toInteger()); + $this->assertSame(0, $this->stringable('nan')->toInteger()); + $this->assertSame(1, $this->stringable('1ab')->toInteger()); + $this->assertSame(2, $this->stringable('2_000')->toInteger()); + } + + public function testToFloat() + { + $this->assertSame(1.23, $this->stringable('1.23')->toFloat()); + $this->assertSame(45.6, $this->stringable(45.6)->toFloat()); + $this->assertSame(.6, $this->stringable('.6')->toFloat()); + $this->assertSame(0.78, $this->stringable('0.78')->toFloat()); + $this->assertSame(90.1, $this->stringable(' 90.1')->toFloat()); + $this->assertSame(0.0, $this->stringable('nan')->toFloat()); + $this->assertSame(1.0, $this->stringable('1.ab')->toFloat()); + $this->assertSame(1e3, $this->stringable('1e3')->toFloat()); + } + + public function testBooleanMethod() + { + $this->assertTrue($this->stringable(true)->toBoolean()); + $this->assertTrue($this->stringable('true')->toBoolean()); + $this->assertFalse($this->stringable('false')->toBoolean()); + $this->assertTrue($this->stringable('1')->toBoolean()); + $this->assertFalse($this->stringable('0')->toBoolean()); + $this->assertTrue($this->stringable('on')->toBoolean()); + $this->assertFalse($this->stringable('off')->toBoolean()); + $this->assertTrue($this->stringable('yes')->toBoolean()); + $this->assertFalse($this->stringable('no')->toBoolean()); + } + + public function testToDate() + { + $current = Carbon::create(2020, 1, 1, 16, 30, 25); + + $this->assertEquals($current, $this->stringable('20-01-01 16:30:25')->toDate()); + $this->assertEquals($current, $this->stringable('1577896225')->toDate('U')); + $this->assertEquals($current, $this->stringable('20-01-01 13:30:25')->toDate(null, 'America/Santiago')); + + $this->assertTrue($this->stringable('2020-01-01')->toDate()->isSameDay($current)); + $this->assertTrue($this->stringable('16:30:25')->toDate()->isSameSecond('16:30:25')); + } + + public function testToDateThrowsException() + { + $this->expectException(\Carbon\Exceptions\InvalidFormatException::class); + + $this->stringable('not a date')->toDate(); + } }
true
Other
laravel
framework
618eeebeb6f78a2c19d567dc7e5e71732ef397ab.json
Add missing citext type mapping (#44237)
src/Illuminate/Database/Console/DatabaseInspectionCommand.php
@@ -24,6 +24,7 @@ abstract class DatabaseInspectionCommand extends Command */ protected $typeMappings = [ 'bit' => 'string', + 'citext' => 'string', 'enum' => 'string', 'geometry' => 'string', 'geomcollection' => 'string',
false
Other
laravel
framework
89b316851eeba4c9e2ea19c87d928b96696f3259.json
Add support for ltree (#44220)
src/Illuminate/Database/Console/DatabaseInspectionCommand.php
@@ -28,6 +28,7 @@ abstract class DatabaseInspectionCommand extends Command 'geometry' => 'string', 'geomcollection' => 'string', 'linestring' => 'string', + 'ltree' => 'string', 'multilinestring' => 'string', 'multipoint' => 'string', 'multipolygon' => 'string',
false
Other
laravel
framework
b9b5c5caceebb4141ac39031d1f1ac6b47847dcd.json
make Vite macroable (#44198)
src/Illuminate/Foundation/Vite.php
@@ -7,9 +7,12 @@ use Illuminate\Support\Collection; use Illuminate\Support\HtmlString; use Illuminate\Support\Str; +use Illuminate\Support\Traits\Macroable; class Vite implements Htmlable { + use Macroable; + /** * The Content Security Policy nonce to apply to all generated tags. *
true
Other
laravel
framework
b9b5c5caceebb4141ac39031d1f1ac6b47847dcd.json
make Vite macroable (#44198)
tests/Foundation/FoundationViteTest.php
@@ -614,6 +614,25 @@ public function testViteCanOverrideHotFilePath() $this->cleanViteHotFile('cold'); } + public function testViteIsMacroable() + { + $this->makeViteManifest([ + 'resources/images/profile.png' => [ + 'src' => 'resources/images/profile.png', + 'file' => 'assets/profile.versioned.png', + ], + ], $buildDir = Str::random()); + Vite::macro('image', function ($asset, $buildDir = null) { + return $this->asset("resources/images/{$asset}", $buildDir); + }); + + $path = ViteFacade::image('profile.png', $buildDir); + + $this->assertSame("https://example.com/{$buildDir}/assets/profile.versioned.png", $path); + + $this->cleanViteManifest($buildDir); + } + protected function makeViteManifest($contents = null, $path = 'build') { app()->singleton('path.public', fn () => __DIR__);
true
Other
laravel
framework
d98bdacba48ec6ea8aa730a73cff9581502d5038.json
Require symfony/uid (#44202)
composer.json
@@ -41,6 +41,7 @@ "symfony/mime": "^6.0", "symfony/process": "^6.0", "symfony/routing": "^6.0", + "symfony/uid": "^6.0", "symfony/var-dumper": "^6.0", "tijsverkoyen/css-to-inline-styles": "^2.2.2", "vlucas/phpdotenv": "^5.4.1", @@ -97,8 +98,7 @@ "phpstan/phpstan": "^1.4.7", "phpunit/phpunit": "^9.5.8", "predis/predis": "^1.1.9|^2.0", - "symfony/cache": "^6.0", - "symfony/uid": "^6.0" + "symfony/cache": "^6.0" }, "provide": { "psr/container-implementation": "1.1|2.0", @@ -169,8 +169,7 @@ "symfony/http-client": "Required to enable support for the Symfony API mail transports (^6.0).", "symfony/mailgun-mailer": "Required to enable support for the Mailgun mail transport (^6.0).", "symfony/postmark-mailer": "Required to enable support for the Postmark mail transport (^6.0).", - "symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0).", - "symfony/uid": "Required to generate ULIDs for Eloquent (^6.0)." + "symfony/psr-http-message-bridge": "Required to use PSR-7 bridging features (^2.0)." }, "config": { "sort-packages": true,
true